node_partition.h
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:2k
开发平台:

MultiPlatform

  1. /*******************************************************************************
  2. +
  3. +  LEDA-R  3.2.3
  4. +
  5. +  node_partition.h
  6. +
  7. +  Copyright (c) 1995  by  Max-Planck-Institut fuer Informatik
  8. +  Im Stadtwald, 66123 Saarbruecken, Germany     
  9. +  All rights reserved.
  10. *******************************************************************************/
  11. #ifndef LEDA_NODE_PARTITION_H
  12. #define LEDA_NODE_PARTITION_H
  13. //------------------------------------------------------------------------------
  14. // node partitions 
  15. //------------------------------------------------------------------------------
  16. #include <LEDA/graph.h>
  17. /*{Manpage {node_partition} {} {Node Partitions}}*/
  18. #include <LEDA/partition.h>
  19. class node_partition : private partition
  20. {
  21. /*{Mdefinition
  22. An instance $P$ of the data type $node_partition$ is a partition of the nodes
  23. of a graph $G$.}*/
  24. public:
  25. void init(const graph& G);
  26. /*{Mcreation P }*/
  27.  node_partition(const graph& G) { init(G); }
  28. /*{Mcreate creates a name var containing for every node $v$ in $G$ a 
  29.             block ${v}$.}*/
  30. ~node_partition()               {}   
  31. /*{Moperations 1.2 4.5}*/
  32. int  same_block(node v, node w)   
  33. { return partition::same_block(partition_item(v->data[2]),
  34.                                partition_item(w->data[2])); }
  35. /*{Mopl      returns true if $v$ and $w$ belong to the
  36.               same block of var, false otherwise.}*/
  37. void union_blocks(node v, node w) 
  38. { partition::union_blocks(partition_item(v->data[2]), 
  39.                           partition_item(w->data[2])); }
  40. /*{Mopl      unites the blocks of var containing nodes
  41.       $v$ and $w$.}*/
  42. void make_rep(node v) 
  43. { partition::set_inf(partition_item(v->data[2]),v); }
  44. node find(node v) 
  45. { return node(partition::inf(partition::find(partition_item(v->data[2])))); }
  46. /*{Mop       returns a canonical representative node of 
  47.       the block that contains node $v$.}*/
  48. node operator()(node v) { return find(v); }
  49. /*{Mfunop    returns var.find($v$). }*/
  50. };
  51. /*{Mimplementation
  52. A node partition for a graph $G$ is implemented by a combination of a 
  53. partition $P$ and a node array of $partition_item$ associating with 
  54. each node in $G$ a partition item in $P$. Initialization takes linear time,
  55. union_blocks takes time $O(1)$ (worst-case), and same_block and find take 
  56. time $O(alpha(n))$ (amortized).  The space requirement is $O(n)$, where $n$ 
  57. is the number of nodes of $G$.}*/
  58. #endif