3 Copyright (c) Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine 2000
5 Distributed under the Boost Software License, Version 1.0.
6 (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
10 <Title>Boost Graph Library: BFSVisitor
</Title>
11 <BODY BGCOLOR=
"#ffffff" LINK=
"#0000ee" TEXT=
"#000000" VLINK=
"#551a8b"
13 <IMG SRC=
"../../../boost.png"
14 ALT=
"C++ Boost" width=
"277" height=
"86">
18 <H1><img src=
"figs/python.gif" alt=
"(Python)"/>BFS Visitor Concept
</H1>
20 This concept defines the visitor interface for
<a
21 href=
"./breadth_first_search.html"><tt>breadth_first_search()
</tt></a>.
22 Users can define a class with the BFS Visitor interface and pass and
23 object of the class to
<tt>breadth_first_search()
</tt>, thereby
24 augmenting the actions taken during the graph search.
26 <h3>Refinement of
</h3>
28 <a href=
"../../utility/CopyConstructible.html">Copy Constructible
</a>
29 (copying a visitor should be a lightweight operation).
37 <TD>A type that is a model of BFS Visitor.
</TD>
42 <TD>An object of type
<tt>V
</tt>.
</TD>
47 <TD>A type that is a model of Graph.
</TD>
52 <TD>An object of type
<tt>G
</tt>.
</TD>
57 <TD>An object of type
<tt>boost::graph_traits
<G
>::edge_descriptor
</tt>.
</TD>
62 <TD>An object of type
<tt>boost::graph_traits
<G
>::vertex_descriptor
</tt>.
</TD>
67 <h3>Associated Types
</h3>
72 <h3>Valid Expressions
</h3>
76 <th>Name
</th><th>Expression
</th><th>Return Type
</th><th>Description
</th>
80 <td>Initialize Vertex
</td>
81 <td><tt>vis.initialize_vertex(s, g)
</tt></td>
82 <td><tt>void
</tt></td>
84 This is invoked on every vertex of the graph before the start of the
90 <td>Discover Vertex
</td>
91 <td><tt>vis.discover_vertex(u, g)
</tt></td>
92 <td><tt>void
</tt></td>
94 This is invoked when a vertex is encountered for the first time.
99 <td>Examine Vertex
</td>
100 <td><tt>vis.examine_vertex(u, g)
</tt></td>
101 <td><tt>void
</tt></td>
103 This is invoked on a vertex as it is popped from the queue. This
104 happens immediately before
<tt>examine_edge()
</tt> is invoked
105 on each of the out-edges of vertex
<tt>u
</tt>.
110 <td>Examine Edge
</td>
111 <td><tt>vis.examine_edge(e, g)
</tt></td>
112 <td><tt>void
</tt></td>
114 This is invoked on every out-edge of each vertex after it is discovered.
121 <td><tt>vis.tree_edge(e, g)
</tt></td>
122 <td><tt>void
</tt></td>
124 This is invoked on each edge as it becomes a member of the edges that
125 form the search tree.
</td>
129 <td>Non-Tree Edge
</td>
130 <td><tt>vis.non_tree_edge(e, g)
</tt></td>
131 <td><tt>void
</tt></td>
133 This is invoked on back or cross edges for directed graphs and cross
134 edges for undirected graphs.
140 <td><tt>vis.gray_target(e, g)
</tt></td>
141 <td><tt>void
</tt></td>
143 This is invoked on the subset of non-tree edges whose target vertex is
144 colored gray at the time of examination. The color gray indicates
145 that the vertex is currently in the queue.
150 <td>Black Target
</td>
151 <td><tt>vis.black_target(e, g)
</tt></td>
152 <td><tt>void
</tt></td>
154 This is invoked on the subset of non-tree edges whose target vertex is
155 colored black at the time of examination. The color black indicates
156 that the vertex has been removed from the queue.
161 <td>Finish Vertex
</td>
162 <td><tt>vis.finish_vertex(u, g)
</tt></td>
163 <td><tt>void
</tt></td>
165 This invoked on a vertex after all of its out edges have been added to the
166 search tree and all of the adjacent vertices have been discovered
167 (but before the out-edges of the adjacent vertices have been examined).
176 <li><a href=
"./bfs_visitor.html"><tt>bfs_visitor
</tt></a>
179 <a name=
"python"></a><h3>Python
</h3>
180 To implement a model of the
<tt>BFSVisitor
</tt> concept in Python,
181 create a new class that derives from the
<tt>BFSVisitor
</tt> type of
182 the graph, which will be
183 named
<tt><i>GraphType
</i>.BFSVisitor
</tt>. The events and syntax are
184 the same as with visitors in C++. Here is an example for the
185 Python
<tt>bgl.Graph
</tt> graph type:
188 class count_tree_edges_bfs_visitor(bgl.Graph.BFSVisitor):
189 def __init__(self, name_map):
190 bgl.Graph.BFSVisitor.__init__(self)
191 self.name_map = name_map
193 def tree_edge(self, e, g):
194 (u, v) = (g.source(e), g.target(e))
196 print self.name_map[u],
198 print self.name_map[v]
203 <a href=
"./visitor_concepts.html">Visitor concepts
</a>
209 <TD nowrap
>Copyright
© 2000-
2001</TD><TD>
210 <A HREF=
"http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek
</A>,
211 Indiana University (
<A
212 HREF=
"mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu
</A>)
<br>
213 <A HREF=
"http://www.boost.org/people/liequan_lee.htm">Lie-Quan Lee
</A>, Indiana University (
<A HREF=
"mailto:llee@cs.indiana.edu">llee@cs.indiana.edu
</A>)
<br>
214 <A HREF=
"http://www.osl.iu.edu/~lums">Andrew Lumsdaine
</A>,
215 Indiana University (
<A
216 HREF=
"mailto:lums@osl.iu.edu">lums@osl.iu.edu
</A>)