biconnected_components.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <HTML>
  2. <!--
  3. Copyright 2001-2004 The Trustees of Indiana University.
  4. Use, modification and distribution is subject to the Boost Software
  5. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. Authors: Douglas Gregor
  8. Jeremy Siek
  9. Andrew Lumsdaine
  10. -->
  11. <Head>
  12. <Title>Boost Graph Library: Biconnected Components and Articulation Points</Title>
  13. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  14. ALINK="#ff0000">
  15. <IMG SRC="../../../boost.png"
  16. ALT="C++ Boost" width="277" height="86">
  17. <BR Clear>
  18. <h1>
  19. <TT>
  20. <img src="figs/python.gif" alt="(Python)"/>
  21. <A NAME="sec:biconnected-components">biconnected_components
  22. </A>
  23. </TT>
  24. and
  25. <tt>articulation_points</tt>
  26. </h1>
  27. <PRE>
  28. <i>// named parameter version</i>
  29. template &lt;typename Graph, typename ComponentMap, typename OutputIterator,
  30. typename P, typename T, typename R&gt;
  31. std::pair&lt;std::size_t, OutputIterator&gt;
  32. biconnected_components(const Graph& g, ComponentMap comp, OutputIterator out,
  33. const bgl_named_params&lt;P, T, R&gt;&amp; params)
  34. template &lt;typename Graph, typename ComponentMap,
  35. typename P, typename T, typename R&gt;
  36. std::size_t
  37. biconnected_components(const Graph& g, ComponentMap comp,
  38. const bgl_named_params&lt;P, T, R&gt;&amp; params)
  39. template &lt;typename Graph, typename OutputIterator,
  40. typename P, typename T, typename R&gt;
  41. OutputIterator articulation_points(const Graph& g, OutputIterator out,
  42. const bgl_named_params&lt;P, T, R&gt;&amp; params)
  43. <i>// non-named parameter version</i>
  44. template &lt;typename Graph, typename ComponentMap, typename OutputIterator,
  45. typename DiscoverTimeMap, typename LowPointMap&gt;
  46. std::pair&lt;std::size_t, OutputIterator&gt;
  47. biconnected_components(const Graph& g, ComponentMap comp, OutputIterator out,
  48. DiscoverTimeMap discover_time, LowPointMap lowpt);
  49. template &lt;typename Graph, typename ComponentMap, typename OutputIterator&gt;
  50. std::pair&lt;std::size_t, OutputIterator&gt;
  51. biconnected_components(const Graph& g, ComponentMap comp, OutputIterator out);
  52. template &lt;typename Graph, typename ComponentMap&gt;
  53. std::size_t biconnected_components(const Graph& g, ComponentMap comp);
  54. <a name="sec:articulation_points">
  55. template &lt;typename Graph, typename OutputIterator&gt;
  56. OutputIterator articulation_points(const Graph& g, OutputIterator out);
  57. </PRE>
  58. <P>
  59. A connected graph is <i>biconnected</i> if the removal of any single
  60. vertex (and all edges incident on that vertex) can not disconnect the
  61. graph. More generally, the biconnected components of a graph are the
  62. maximal subsets of vertices such that the removal of a vertex from a
  63. particular component will not disconnect the component. Unlike
  64. connected components, vertices may belong to multiple biconnected
  65. components: those vertices that belong to more than one biconnected
  66. component are called <em>articulation points</em> or, equivalently,
  67. <em>cut vertices</em>. Articulation points are vertices whose removal
  68. would increase the number of connected components in the graph. Thus,
  69. a graph without articulation points is biconnected. The following
  70. figure illustrates the articulation points and biconnected components
  71. of a small graph:
  72. <p><center><img src="figs/biconnected.png"></center>
  73. <p>Vertices can be present in multiple biconnected components, but each
  74. edge can only be contained in a single biconnected component. The
  75. output of the <tt>biconnected_components</tt> algorithm records the
  76. biconnected component number of each edge in the property map
  77. <tt>comp</tt>. Articulation points will be emitted to the (optional)
  78. output iterator argument to <tt>biconnected_components</tt>, or can be
  79. computed without the use of a biconnected component number map via
  80. <tt>articulation_points</tt>. These functions return the number of
  81. biconnected components, the articulation point output iterator, or a
  82. pair of these quantities, depending on what information was
  83. recorded.
  84. <p>The algorithm implemented is due to Tarjan [<a href="bibliography.html#tarjan72:dfs_and_linear_algo">41</a>].
  85. <H3>Where Defined</H3>
  86. <P>
  87. <a href="../../../boost/graph/biconnected_components.hpp"><TT>boost/graph/biconnected_components.hpp</TT></a>
  88. <h3>Parameters</h3>
  89. IN: <tt>const Graph&amp; g</tt>
  90. <blockquote>
  91. An undirected graph. The graph type must be a model of <a
  92. href="VertexListGraph.html">Vertex List Graph</a> and <a
  93. href="IncidenceGraph.html">Incidence Graph</a>.<br>
  94. <b>Python</b>: The parameter is named <tt>graph</tt>.
  95. </blockquote>
  96. OUT: <tt>ComponentMap c</tt>
  97. <blockquote>
  98. The algorithm computes how many biconnected components are in the graph,
  99. and assigning each component an integer label. The algorithm then
  100. records which component each edge in the graph belongs to by
  101. recording the component number in the component property map. The
  102. <tt>ComponentMap</tt> type must be a model of <a
  103. href="../../property_map/doc/WritablePropertyMap.html">Writable Property
  104. Map</a>. The value type should be an integer type, preferably the same
  105. as the <tt>edges_size_type</tt> of the graph. The key type must be
  106. the graph's edge descriptor type.<br>
  107. <b>Default</b>: <tt>dummy_property_map</tt>.<br>
  108. <b>Python</b>: Must be an <tt>edge_int_map</tt> for the graph.<br>
  109. <b>Python default</b>: <tt>graph.get_edge_int_map("bicomponent")</tt>
  110. </blockquote>
  111. OUT: <tt>OutputIterator out</tt>
  112. <blockquote>
  113. The algorithm writes articulation points via this output
  114. iterator and returns the resulting iterator.<br>
  115. <b>Default</b>: a dummy iterator that ignores values written to it.<br>
  116. <b>Python</b>: this parameter is not used in Python. Instead, both
  117. algorithms return a Python <tt>list</tt> containing the articulation
  118. points.
  119. </blockquote>
  120. <h3>Named Parameters</h3>
  121. IN: <tt>vertex_index_map(VertexIndexMap i_map)</tt>
  122. <blockquote>
  123. This maps each vertex to an integer in the range <tt>[0,
  124. num_vertices(g))</tt>. The type
  125. <tt>VertexIndexMap</tt> must be a model of
  126. <a href="../../property_map/doc/ReadablePropertyMap.html">Readable Property Map</a>. The value type of the map must be an
  127. integer type. The vertex descriptor type of the graph needs to be
  128. usable as the key type of the map.<br>
  129. <b>Default:</b> <tt>get(vertex_index, g)</tt><br>
  130. <b>Python</b>: Unsupported parameter.
  131. </blockquote>
  132. UTIL/OUT: <tt>discover_time_map(DiscoverTimeMap discover_time)</tt>
  133. <blockquote>
  134. The discovery time of each vertex in the depth-first search. The
  135. type <tt>DiscoverTimeMap</tt> must be a model of <a
  136. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write
  137. Property Map</a>. The value type of the map must be an integer
  138. type. The vertex descriptor type of the graph needs to be usable as
  139. the key type of the map.<br>
  140. <b>Default</b>: an <a
  141. href="../../property_map/doc/iterator_property_map.html">
  142. </tt>iterator_property_map</tt></a> created from a
  143. <tt>std::vector</tt> of <tt>vertices_size_type</tt> of size
  144. <tt>num_vertices(g)</tt> and using <tt>get(vertex_index, g)</tt> for
  145. the index map.<br>
  146. <b>Python</b>: Unsupported parameter.
  147. </blockquote>
  148. UTIL/OUT: <tt>lowpoint_map(LowPointMap lowpt)</tt>
  149. <blockquote>
  150. The low point of each vertex in the depth-first search, which is the
  151. smallest vertex reachable from a given vertex with at most one back
  152. edge. The type <tt>LowPointMap</tt> must be a model of <a
  153. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write
  154. Property Map</a>. The value type of the map must be an integer
  155. type. The vertex descriptor type of the graph needs to be usable as
  156. the key type of the map.<br>
  157. <b>Default</b>: an <a
  158. href="../../property_map/doc/iterator_property_map.html">
  159. </tt>iterator_property_map</tt></a> created from a
  160. <tt>std::vector</tt> of <tt>vertices_size_type</tt> of size
  161. <tt>num_vertices(g)</tt> and using <tt>get(vertex_index, g)</tt> for
  162. the index map.<br>
  163. <b>Python</b>: Unsupported parameter.
  164. </blockquote>
  165. UTIL/OUT: <tt>predecessor_map(PredecessorMap p_map)</tt>
  166. <blockquote>
  167. The predecessor map records the depth first search tree.
  168. The <tt>PredecessorMap</tt> type
  169. must be a <a
  170. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write
  171. Property Map</a> whose key and value types are the same as the vertex
  172. descriptor type of the graph.<br>
  173. <b>Default:</b> an <a
  174. href="../../property_map/doc/iterator_property_map.html">
  175. </tt>iterator_property_map</tt></a> created from a
  176. <tt>std::vector</tt> of <tt>vertex_descriptor</tt> of size
  177. <tt>num_vertices(g)</tt> and using <tt>get(vertex_index, g)</tt> for
  178. the index map.<br>
  179. <b>Python</b>: Must be a <tt>vertex_vertex_map</tt> for the graph.<br>
  180. </blockquote>
  181. IN: <tt>visitor(DFSVisitor vis)</tt>
  182. <blockquote>
  183. A visitor object that is invoked inside the algorithm at the
  184. event-points specified by the <a href="./DFSVisitor.html">DFS
  185. Visitor</a> concept. The visitor object is passed by value <a
  186. href="#1">[1]</a>. <br> <b>Default:</b>
  187. <tt>dfs_visitor&lt;null_visitor&gt;</tt><br>
  188. <b>Python</b>: The parameter should be an object that derives from
  189. the <a href="DFSVisitor.html#python"><tt>DFSVisitor</tt></a> type of
  190. the graph.
  191. </blockquote>
  192. <H3>Complexity</H3>
  193. <P>
  194. The time complexity for the biconnected components and articulation
  195. points algorithms
  196. <i>O(V + E)</i>.
  197. <P>
  198. <H3>Example</H3>
  199. <P> The file <a
  200. href="../example/biconnected_components.cpp"><tt>examples/biconnected_components.cpp</tt></a>
  201. contains an example of calculating the biconnected components and
  202. articulation points of an undirected graph.
  203. <h3>Notes</h3>
  204. <p><a name="1">[1]</a>
  205. Since the visitor parameter is passed by value, if your visitor
  206. contains state then any changes to the state during the algorithm
  207. will be made to a copy of the visitor object, not the visitor object
  208. passed in. Therefore you may want the visitor to hold this state by
  209. pointer or reference.
  210. <br>
  211. <HR>
  212. <TABLE>
  213. <TR valign=top>
  214. <TD nowrap>Copyright &copy; 2000-2004</TD><TD>
  215. <A HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</A>, Indiana
  216. University (<A
  217. HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
  218. <a href="http://www.boost.org/people/doug_gregor.html">Doug Gregor</a>, Indiana University
  219. </TD></TR></TABLE>
  220. </BODY>
  221. </HTML>