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>DFS Visitor
</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)"/>DFS Visitor Concept
</H1>
20 This concept defines the visitor interface for
<a
21 href=
"./depth_first_search.html"><tt>depth_first_search()
</tt></a>.
22 Users can define a class with the DFS Visitor interface and pass an
23 object of the class to
<tt>depth_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).
36 <TD>A type that is a model of DFS Visitor.
</TD>
41 <TD>An object of type
<tt>V
</tt>.
</TD>
46 <TD>A type that is a model of Graph.
</TD>
51 <TD>An object of type
<tt>G
</tt>.
</TD>
56 <TD>An object of type
<tt>boost::graph_traits
<G
>::edge_descriptor
</tt>.
</TD>
61 <TD>An object of type
<tt>boost::graph_traits
<G
>::vertex_descriptor
</tt>.
</TD>
66 <h3>Associated Types
</h3>
71 <h3>Valid Expressions
</h3>
75 <th>Name
</th><th>Expression
</th><th>Return Type
</th><th>Description
</th>
79 <td>Initialize Vertex
</td>
80 <td><tt>vis.initialize_vertex(s, g)
</tt></td>
81 <td><tt>void
</tt></td>
83 This is invoked on every vertex of the graph before the start of the
90 <td><tt>vis.start_vertex(s, g)
</tt></td>
91 <td><tt>void
</tt></td>
93 This is invoked on the source vertex once before the start of the
99 <td>Discover Vertex
</td>
100 <td><tt>vis.discover_vertex(u, g)
</tt></td>
101 <td><tt>void
</tt></td>
103 This is invoked when a vertex is encountered for the first time.
108 <td>Examine Edge
</td>
109 <td><tt>vis.examine_edge(e, g)
</tt></td>
110 <td><tt>void
</tt></td>
112 This is invoked on every out-edge of each vertex after it is discovered.
119 <td><tt>vis.tree_edge(e, g)
</tt></td>
120 <td><tt>void
</tt></td>
122 This is invoked on each edge as it becomes a member of the edges that
123 form the search tree.
</td>
128 <td><tt>vis.back_edge(e, g)
</tt></td>
129 <td><tt>void
</tt></td>
131 This is invoked on the back edges in the graph. For an undirected
132 graph there is some ambiguity between tree edges and back edges since
133 the edge
<i>(u,v)
</i> and
<i>(v,u)
</i> are the same edge, but both the
134 <tt>tree_edge()
</tt> and
<tt>back_edge()
</tt> functions will be
135 invoked. One way to resolve this ambiguity is to record the tree
136 edges, and then disregard the back-edges that are already marked as
137 tree edges. An easy way to record tree edges is to record
138 predecessors at the
<tt>tree_edge
</tt> event point.
143 <td>Forward or Cross Edge
</td>
144 <td><tt>vis.forward_or_cross_edge(e, g)
</tt></td>
145 <td><tt>void
</tt></td>
147 This is invoked on forward or cross edges in the graph. In an
148 undirected graph this method is never called.
154 <td><tt>vis.finish_edge(e, g)
</tt></td>
155 <td><tt>void
</tt></td>
157 This is invoked on each non-tree edge as well as on each tree edge after
158 <tt>finish_vertex
</tt> has been called on its target vertex.
</td>
162 <td>Finish Vertex
</td>
163 <td><tt>vis.finish_vertex(u, g)
</tt></td>
164 <td><tt>void
</tt></td>
166 This is invoked on vertex
<tt>u
</tt> after
<tt>finish_vertex
</tt> has
167 been called for all the vertices in the DFS-tree rooted at vertex
168 <tt>u
</tt>. If vertex
<tt>u
</tt> is a leaf in the DFS-tree, then
169 the
<tt>finish_vertex
</tt> function is called on
<tt>u
</tt> after
170 all the out-edges of
<tt>u
</tt> have been examined.
179 <li><a href=
"./dfs_visitor.html"><tt>dfs_visitor
</tt></a>
182 <a name=
"python"></a>
185 To implement a model of the
<tt>DFSVisitor
</tt> concept in Python,
186 create a new class that derives from the
<tt>DFSVisitor
</tt> type of
187 the graph, which will be
188 named
<tt><i>GraphType
</i>.DFSVisitor
</tt>. The events and syntax are
189 the same as with visitors in C++. Here is an example for the
190 Python
<tt>bgl.Graph
</tt> graph type:
193 class count_tree_edges_dfs_visitor(bgl.Graph.DFSVisitor):
194 def __init__(self, name_map):
195 bgl.Graph.DFSVisitor.__init__(self)
196 self.name_map = name_map
198 def tree_edge(self, e, g):
199 (u, v) = (g.source(e), g.target(e))
201 print self.name_map[u],
203 print self.name_map[v]
210 <TD nowrap
>Copyright
© 2000-
2001</TD><TD>
211 <A HREF=
"http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek
</A>,
212 Indiana University (
<A
213 HREF=
"mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu
</A>)
<br>
214 <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>
215 <A HREF=
"http://www.osl.iu.edu/~lums">Andrew Lumsdaine
</A>,
216 Indiana University (
<A
217 HREF=
"mailto:lums@osl.iu.edu">lums@osl.iu.edu
</A>)