breadth_first_visit.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <HTML>
  2. <!--
  3. Copyright (c) Jeremy Siek 2000, 2001
  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: Breadth-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. <H1><A NAME="sec:bfv"><img src="figs/python.gif" alt="(Python)"/>
  16. <TT>breadth_first_visit</TT>
  17. </H1>
  18. <P>
  19. <PRE>
  20. template &lt;class <a href="./IncidenceGraph.html">IncidenceGraph</a>, class P, class T, class R&gt;
  21. void breadth_first_visit(IncidenceGraph& G,
  22. typename graph_traits&lt;IncidenceGraph&gt;::vertex_descriptor s,
  23. const bgl_named_params&lt;P, T, R&gt;&amp; params);
  24. template &lt;class <a href="./IncidenceGraph.html">IncidenceGraph</a>, class <a href="./Buffer.html">Buffer</a>, class <a href="./BFSVisitor.html">BFSVisitor</a>, class ColorMap&gt;
  25. void breadth_first_visit
  26. (const IncidenceGraph&amp; g,
  27. typename graph_traits&lt;IncidenceGraph&gt;::vertex_descriptor s,
  28. Buffer&amp; Q, BFSVisitor vis, ColorMap color)
  29. </PRE>
  30. This function is basically the same as <tt>breadth_first_search()</tt>
  31. except that the color markers are not initialized in the
  32. algorithm. The user is responsible for making sure the color for every
  33. vertex is white before calling the algorithm. With this difference,
  34. the graph type is only required to be an <a
  35. href="./IncidenceGraph.html">Incidence Graph</a> instead of a <a
  36. href="./VertexListGraph.html">Vertex List Graph</a>. Also, this
  37. difference allows for more flexibility in the color property map. For
  38. example, one could use a map that only implements a partial function
  39. on the vertices, which could be more space efficient when the search
  40. only reaches a small portion of the graph.
  41. <H3>Where Defined</H3>
  42. <P>
  43. <a href="../../../boost/graph/breadth_first_search.hpp"><TT>boost/graph/breadth_first_search.hpp</TT></a>
  44. <h3>Parameters</h3>
  45. IN: <tt>IncidenceGraph&amp; g</tt>
  46. <blockquote>
  47. A directed or undirected graph. The graph type must
  48. be a model of <a href="./IncidenceGraph.html">Incidence Graph</a>.<br>
  49. <b>Python</b>: The parameter is named <tt>graph</tt>.
  50. </blockquote>
  51. IN: <tt>vertex_descriptor s</tt>
  52. <blockquote>
  53. The source vertex where the search is started.<br>
  54. <b>Python</b>: The parameter is named <tt>root_vertex</tt>.
  55. </blockquote>
  56. <h3>Named Parameters</h3>
  57. IN: <tt>visitor(BFSVisitor vis)</tt>
  58. <blockquote>
  59. A visitor object that is invoked inside the algorithm at the
  60. event-points specified by the <a href="BFSVisitor.html">BFS
  61. Visitor</a> concept. The visitor object is passed by value <a
  62. href="#1">[1]</a>.<br> <b>Default:</b>
  63. <tt>bfs_visitor&lt;null_visitor&gt;</tt><br>
  64. <b>Python</b>: The parameter should be an object that derives from
  65. the <a href="BFSVisitor.html#python"><tt>BFSVisitor</tt></a> type of the graph.
  66. </blockquote>
  67. UTIL/OUT: <tt>color_map(ColorMap color)</tt>
  68. <blockquote>
  69. This is used by the algorithm to keep track of its progress through
  70. the graph. The type <tt>ColorMap</tt> must be a model of <a
  71. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write
  72. Property Map</a> and its key type must be the graph's vertex
  73. descriptor type and the value type of the color map must model
  74. <a href="./ColorValue.html">ColorValue</a>.<br>
  75. <b>Default:</b> <tt>get(vertex_color, g)</tt><br>
  76. <b>Python</b>: The color map must be a <tt>vertex_color_map</tt> for
  77. the graph.
  78. </blockquote>
  79. UTIL: <tt>buffer(Buffer&amp; Q)</tt>
  80. <blockquote>
  81. The queue used to determine the order in which vertices will be
  82. discovered. If a FIFO queue is used, then the traversal will
  83. be according to the usual BFS ordering. Other types of queues
  84. can be used, but the traversal order will be different.
  85. For example Dijkstra's algorithm can be implemented
  86. using a priority queue. The type <tt>Buffer</tt> must be a model of
  87. <a href="./Buffer.html">Buffer</a>.<br>
  88. <b>Default:</b> <tt>boost::queue</tt><br>
  89. <b>Python</b>: The buffer must derive from the <a
  90. href="./Buffer.html">Buffer</a> type for the graph.
  91. </blockquote>
  92. <H3><A NAME="SECTION001330300000000000000">
  93. Complexity</A>
  94. </H3>
  95. <P>
  96. The time complexity is <i>O(E)</i>.
  97. <P>
  98. <h3>Visitor Event Points</h3>
  99. <ul>
  100. <li><b><tt>vis.examine_vertex(u, g)</tt></b>r is invoked in each
  101. vertex as it is removed from the queue.
  102. <li><b><tt>vis.examine_edge(e, g)</tt></b> is invoked on every out-edge
  103. of each vertex immediately after the vertex is removed from the queue.
  104. <li><b><tt>vis.tree_edge(e, g)</tt></b> is invoked (in addition to
  105. <tt>examine_edge()</tt>) if the edge is a tree edge. The
  106. target vertex of edge <tt>e</tt> is discovered at this time.
  107. <li><b><tt>vis.discover_vertex(u, g)</tt></b> is invoked the first time the
  108. algorithm encounters vertex <i>u</i>. All vertices closer to the
  109. source vertex have been discovered, and vertices further from the
  110. source have not yet been discovered.
  111. <li><b><tt>vis.non_tree_edge(e, g)</tt></b> is invoked (in addition to
  112. <tt>examine_edge()</tt>) if the edge is not a tree edge.
  113. <li><b><tt>vis.gray_target(e, g)</tt></b> is invoked (in addition to
  114. <tt>non_tree_edge()</tt>) if the target vertex is colored gray at the
  115. time of examination. The color gray indicates that
  116. the vertex is currently in the queue.
  117. <li><b><tt>vis.black_target(e, g)</tt></b> is invoked (in addition to
  118. <tt>non_tree_edge()</tt>) if the target vertex is colored black at the
  119. time of examination. The color black indicates that the
  120. vertex is no longer in the queue.
  121. <li><b><tt>vis.finish_vertex(u, g)</tt></b> is invoked after all of the out
  122. edges of <i>u</i> have been examined and all of the adjacent vertices
  123. have been discovered.
  124. </ul>
  125. <h3>See Also</h3>
  126. <a href="./breadth_first_search.html"><tt>breadth_first_search()</tt></a>,
  127. <a href="./bfs_visitor.html"><tt>bfs_visitor</tt></a>, and
  128. <a href="./depth_first_search.html"><tt>depth_first_search()</tt></a>
  129. <h3>Notes</h3>
  130. <p><a name="1">[1]</a>
  131. Since the visitor parameter is passed by value, if your visitor
  132. contains state then any changes to the state during the algorithm
  133. will be made to a copy of the visitor object, not the visitor object
  134. passed in. Therefore you may want the visitor to hold this state by
  135. pointer or reference.
  136. <br>
  137. <HR>
  138. <TABLE>
  139. <TR valign=top>
  140. <TD nowrap>Copyright &copy; 2000-2001</TD><TD>
  141. <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>)
  142. </TD></TR></TABLE>
  143. </BODY>
  144. </HTML>