depth_first_visit.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <HTML>
  2. <!--
  3. Copyright (c) Jeremy Siek 2000
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <Head>
  9. <Title>Boost Graph Library: Depth-First Visit</Title>
  10. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  11. ALINK="#ff0000">
  12. <IMG SRC="../../../boost.png"
  13. ALT="C++ Boost" width="277" height="86">
  14. <BR Clear>
  15. <H2><A NAME="sec:dfs"></A>
  16. <img src="figs/python.gif" alt="(Python)"/>
  17. <TT>depth_first_visit</TT>
  18. </H2>
  19. <P>
  20. <PRE>
  21. template &lt;class <a href="./IncidenceGraph.html">IncidenceGraph</a>, class <a href="./DFSVisitor.html">DFSVisitor</a>, class ColorMap&gt;
  22. void depth_first_visit(IncidenceGraph& g,
  23. typename graph_traits&lt;IncidenceGraph&gt;::vertex_descriptor s,
  24. DFSVisitor&amp; vis, ColorMap color)
  25. template &lt;class <a href="./IncidenceGraph.html">IncidenceGraph</a>, class <a href="./DFSVisitor.html">DFSVisitor</a>, class ColorMap,
  26. class TerminatorFunc&gt;
  27. void depth_first_visit(IncidenceGraph& g,
  28. typename graph_traits&lt;IncidenceGraph&gt;::vertex_descriptor s,
  29. DFSVisitor&amp; vis, ColorMap color, TerminatorFunc func = TerminatorFunc())
  30. </PRE>
  31. <P>
  32. This function visits all of the vertices in the same connected
  33. component as the source vertex <tt>s</tt>, using the <a
  34. href="./graph_theory_review.html#sec:dfs-algorithm">depth-first
  35. pattern</a>. The main purpose of the function is for the
  36. implementation of <TT>depth_first_search()</TT> though sometimes it is
  37. useful on its own.
  38. <p>
  39. The <tt>DFSVisitor</tt> supplied by the user determines what
  40. actions are taken at each event-point within the algorithm.
  41. <p>
  42. The <tt>ColorMap</tt> is used by the algorithm to keep track
  43. of which vertices have been visited.
  44. <p>The second variant can be used, for example, to find all marked vertices
  45. reachable from a start vertex by a path which does not contain any another
  46. marked vertices.
  47. <P>
  48. <h3>Where Defined:</h3>
  49. <a href="../../../boost/graph/depth_first_search.hpp"><TT>boost/graph/depth_first_search.hpp</TT></a>
  50. <h3>Parameters</h3>
  51. IN <tt>IncidenceGraph&amp; g</tt>
  52. <blockquote>
  53. A directed or undirected graph. The graph's type must be a model of
  54. <a href="./IncidenceGraph.html">Incidence Graph</a>.<br>
  55. <b>Python</b>: The parameter is named <tt>graph</tt>.
  56. </blockquote>
  57. IN: <tt>vertex_descriptor s</tt>
  58. <blockquote>
  59. The source vertex from which to start the search.<br>
  60. <b>Python</b>: The parameter is named <tt>root_vertex</tt>.
  61. </blockquote>
  62. IN: <tt>DFSVisitor visitor</tt>
  63. <blockquote>
  64. A visitor object that is invoked inside the algorithm at the
  65. event-points specified by the <a href="./DFSVisitor.html">DFS
  66. Visitor</a> concept. The visitor object is passed by value <a
  67. href="#1">[1]</a>.<br>
  68. <b>Python</b>: The parameter should be an object that derives from
  69. the <a href="DFSVisitor.html#python"><tt>DFSVisitor</tt></a> type of
  70. the graph.
  71. </blockquote>
  72. UTIL: <tt>ColorMap color</tt>
  73. <blockquote>
  74. This is used by the algorithm to keep track of its progress through
  75. the graph. The type <tt>ColorMap</tt> must be a model of <a
  76. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write
  77. Property Map</a> and its key type must be the graph's vertex
  78. descriptor type and the value type of the color map map must model
  79. <a href="./ColorValue.html">Color Value</a>.<br>
  80. <b>Python</b>: The color map must be a <tt>vertex_color_map</tt> for
  81. the graph.
  82. </blockquote>
  83. IN: <tt>TerminatorFunc func</tt>
  84. <blockquote>
  85. A function object callable with two parameters - the descriptor of
  86. vertex and the graph instance - and returning bool. The call is made
  87. immediately after call to 'discover_vertex' visitor
  88. event. If <tt>true</tt> is returned, the out edges of the vertex are
  89. not examined, as if they don't exist.<br>
  90. <b>Python</b>: Unsupported parameter.
  91. </blockquote>
  92. <P>
  93. <h3>Complexity</h3>
  94. Time complexity is <i>O(E)</i>.
  95. <h3>Notes</h3>
  96. <p><a name="1">[1]</a>
  97. Since the visitor parameter is passed by value, if your visitor
  98. contains state then any changes to the state during the algorithm
  99. will be made to a copy of the visitor object, not the visitor object
  100. passed in. Therefore you may want the visitor to hold this state by
  101. pointer or reference.
  102. <br>
  103. <HR>
  104. <TABLE>
  105. <TR valign=top>
  106. <TD nowrap>Copyright &copy; 2000-2001</TD><TD>
  107. <A HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</A>, Indiana University (<A HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)
  108. </TD></TR></TABLE>
  109. </BODY>
  110. </HTML>