make_connected.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <HTML>
  2. <!-- Copyright 2007 Aaron Windsor
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. -->
  7. <Head>
  8. <Title>Boost Graph Library: make_connected</Title>
  9. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  10. ALINK="#ff0000">
  11. <IMG SRC="../../../boost.png"
  12. ALT="C++ Boost" width="277" height="86">
  13. <BR Clear>
  14. <H1><tt>make_connected</tt></H1>
  15. <p>
  16. <pre>
  17. template &lt;typename Graph, typename VertexIndexMap, typename AddEdgeVisitor&gt;
  18. make_connected(Graph& g, VertexIndexMap vm, AddEdgeVisitor& vis);
  19. </pre>
  20. <p>
  21. A undirected graph <i>G</i> is connected if, for every pair of vertices
  22. <i>u,v</i> in <i>G</i>, there is a path from <i>u</i> to <i>v</i>.
  23. <tt>make_connected</tt> adds the minimum number of edges needed to make the
  24. input graph connected. The algorithm first identifies all of the
  25. <a href="./connected_components.html">connected components</a> in the graph,
  26. then adds edges to connect those components together in a path. For example, if
  27. a graph contains three connected components <i>A</i>, <i>B</i>, and <i>C</i>,
  28. <tt>make_connected</tt> will add two edges. The two edges added might consist
  29. of one connecting a vertex in <i>A</i> with a vertex in <i>B</i> and one
  30. connecting a vertex in <i>B</i> with a vertex in <i>C</i>.
  31. <p>
  32. The default behavior of <tt>make_connected</tt> is to modify the graph
  33. <tt>g</tt> by calling <tt>add_edge(u,v,g)</tt> for every pair of vertices
  34. <i>(u,v)</i> where an edge needs to be added to connect <tt>g</tt>. This
  35. behavior can be overriden by providing a vistor as the <tt>AddEdgeVisitor</tt>
  36. parameter. The only requirement for an <tt>AddEdgeVisitor</tt> is that it
  37. define a member function with the following signature:
  38. <pre>
  39. template &lt;typename Graph, typename Vertex&gt;
  40. void visit_vertex_pair(Vertex u, Vertex v, Graph& g);
  41. </pre>
  42. This event point can also be used as a hook to update the underlying edge
  43. index map automatically as edges are added. See the
  44. documentation for the <a href="./AddEdgeVisitor.html">AddEdgeVisitor</a>
  45. concept for more information.
  46. <H3>Where Defined</H3>
  47. <P>
  48. <a href="../../../boost/graph/make_connected.hpp">
  49. <TT>boost/graph/make_connected.hpp</TT>
  50. </a>
  51. <h3>Parameters</h3>
  52. IN/OUT: <tt>Graph&amp; g</tt>
  53. <blockquote>
  54. An undirected graph. The graph type must be a model of <a
  55. href="VertexListGraph.html">Vertex List Graph</a>, <a
  56. href="IncidenceGraph.html">Incidence Graph</a>, and
  57. a <a href="MutableGraph.html">Mutable Graph</a><br>
  58. </blockquote>
  59. IN: <tt>VertexIndexMap vm</tt>
  60. <blockquote>
  61. A <a href="../../property_map/doc/ReadablePropertyMap.html">Readable Property Map
  62. </a> that maps vertices from <tt>g</tt> to distinct integers in the range
  63. <tt>[0, num_vertices(g) )</tt><br>
  64. <b>Default</b>: <tt>get(vertex_index,g)</tt><br>
  65. </blockquote>
  66. IN: <tt>AddEdgeVisitor</tt>
  67. <blockquote>
  68. A model of <a href="AddEdgeVisitor.html">AddEdgeVisitor
  69. </a>.<br>
  70. <b>Default</b>: <tt>default_add_edge_visitor</tt>, a class defines
  71. <tt>visit_vertex_pair</tt> to dispatch
  72. its calls to <tt>add_edge</tt>.
  73. </blockquote>
  74. <h3>Complexity</h3>
  75. On a graph with <i>n</i> vertices and <i>m</i> edges, <tt>make_connected</tt>
  76. runs in time <i>O(n + m)</i>
  77. <H3>Example</H3>
  78. <P>
  79. <a href="../example/make_connected.cpp">
  80. <TT>../example/make_connected.cpp</TT>
  81. </a>
  82. <h3>See Also</h3>
  83. <a href="planar_graphs.html">Planar Graphs in the Boost Graph Library</a>
  84. <br>
  85. <HR>
  86. Copyright &copy; 2007 Aaron Windsor (<a href="mailto:aaron.windsor@gmail.com">
  87. aaron.windsor@gmail.com</a>)
  88. </BODY>
  89. </HTML>