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.
153 <td>Finish Vertex</td>
154 <td><tt>vis.finish_vertex(u, g)</tt></td>
155 <td><tt>void</tt></td>
157 This is invoked on vertex <tt>u</tt> after <tt>finish_vertex</tt> has
158 been called for all the vertices in the DFS-tree rooted at vertex
159 <tt>u</tt>. If vertex <tt>u</tt> is a leaf in the DFS-tree, then
160 the <tt>finish_vertex</tt> function is called on <tt>u</tt> after
161 all the out-edges of <tt>u</tt> have been examined.
170 <li><a href="./dfs_visitor.html"><tt>dfs_visitor</tt></a>
173 <a name="python"></a>
176 To implement a model of the <tt>DFSVisitor</tt> concept in Python,
177 create a new class that derives from the <tt>DFSVisitor</tt> type of
178 the graph, which will be
179 named <tt><i>GraphType</i>.DFSVisitor</tt>. The events and syntax are
180 the same as with visitors in C++. Here is an example for the
181 Python <tt>bgl.Graph</tt> graph type:
184 class count_tree_edges_dfs_visitor(bgl.Graph.DFSVisitor):
185 def __init__(self, name_map):
186 bgl.Graph.DFSVisitor.__init__(self)
187 self.name_map = name_map
189 def tree_edge(self, e, g):
190 (u, v) = (g.source(e), g.target(e))
192 print self.name_map[u],
194 print self.name_map[v]
201 <TD nowrap>Copyright © 2000-2001</TD><TD>
202 <A HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</A>,
203 Indiana University (<A
204 HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
205 <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>
206 <A HREF="http://www.osl.iu.edu/~lums">Andrew Lumsdaine</A>,
207 Indiana University (<A
208 HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)