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: Dijkstra 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)"/>Dijkstra Visitor Concept
</H1>
20 This concept defines the visitor interface for
<a
21 href=
"./dijkstra_shortest_paths.html"><tt>dijkstra_shortest_paths()
</tt></a>
22 and related algorithms. The user can create a class that matches this
23 interface, and then pass objects of the class into
24 <tt>dijkstra_shortest_paths()
</tt> to augment the actions taken during
27 <h3>Refinement of
</h3>
29 <a href=
"../../utility/CopyConstructible.html">Copy Constructible
</a>
30 (copying a visitor should be a lightweight operation).
38 <TD>A type that is a model of Dijkstra Visitor.
</TD>
43 <TD>An object of type
<tt>V
</tt>.
</TD>
48 <TD>A type that is a model of Graph.
</TD>
53 <TD>An object of type
<tt>G
</tt>.
</TD>
58 <TD>An object of type
<tt>boost::graph_traits
<G
>::edge_descriptor
</tt>.
</TD>
62 <TD><tt>s,u,v
</tt></TD>
63 <TD>An object of type
<tt>boost::graph_traits
<G
>::vertex_descriptor
</tt>.
</TD>
67 <TD><tt>DistanceMap
</tt></TD>
68 <TD>A type that is a model of
<a href=
"../../property_map/doc/ReadWritePropertyMap.html">Read/Write Property Map
</a>.
</TD>
73 <TD>An object of type
<tt>DistanceMap
</tt>.
</TD>
77 <TD><tt>WeightMap
</tt></TD>
78 <TD>A type that is a model of
<a href=
"../../property_map/doc/ReadWritePropertyMap.html">Readable Property Map
</a>.
</TD>
83 <TD>An object of type
<tt>WeightMap
</tt>.
</TD>
88 <h3>Associated Types
</h3>
93 <h3>Valid Expressions
</h3>
97 <th>Name
</th><th>Expression
</th><th>Return Type
</th><th>Description
</th>
101 <td>Initialize Vertex
</td>
102 <td><tt>vis.initialize_vertex(u, g)
</tt></td>
103 <td><tt>void
</tt></td>
105 This is invoked one each vertex of the graph when it is initialized.
110 <td>Examine Vertex
</td>
111 <td><tt>vis.examine_vertex(u, g)
</tt></td>
112 <td><tt>void
</tt></td>
114 This is invoked on a vertex as it is popped from the queue. This
115 happens immediately before
<tt>examine_edge()
</tt> is invoked
116 on each of the out-edges of vertex
<tt>u
</tt>.
121 <td>Examine Edge
</td>
122 <td><tt>vis.examine_edge(e, g)
</tt></td>
123 <td><tt>void
</tt></td>
125 This is invoked on every out-edge of each vertex after it is discovered.
130 <td>Discover Vertex
</td>
131 <td><tt>vis.discover_vertex(u, g)
</tt></td>
132 <td><tt>void
</tt></td>
134 This is invoked when a vertex is encountered for the first time.
139 <td>Edge Relaxed
</td>
140 <td><tt>vis.edge_relaxed(e, g)
</tt></td>
141 <td><tt>void
</tt></td>
143 Upon examination, if the following condition holds then the edge
144 is relaxed (its distance is reduced), and this method is invoked.
<br>
146 tie(u,v) = incident(e, g);
<br>
147 D d_u = get(d, u), d_v = get(d, v);
<br>
148 W w_e = get(w, e);
<br>
149 assert(compare(combine(d_u, w_e), d_v));
<br>
155 <td>Edge Not Relaxed
</td>
156 <td><tt>vis.edge_not_relaxed(e, g)
</tt></td>
157 <td><tt>void
</tt></td>
159 Upon examination, if the edge is not relaxed (see above) then
160 this method is invoked.
165 <td>Finish Vertex
</td>
166 <td><tt>vis.finish_vertex(u, g)
</tt></td>
167 <td><tt>void
</tt></td>
169 This invoked on a vertex after all of its out edges have been added to the
170 search tree and all of the adjacent vertices have been discovered
171 (but before their out-edges have been examined).
180 <li><a href=
"./dijkstra_visitor.html"><tt>dijkstra_visitor
</tt></a>
183 <a name=
"python"></a>
186 To implement a model of the
<tt>DijkstraVisitor
</tt> concept in Python,
187 create a new class that derives from the
<tt>DijkstraVisitor
</tt> type of
188 the graph, which will be
189 named
<tt><i>GraphType
</i>.DijkstraVisitor
</tt>. The events and syntax are
190 the same as with visitors in C++. Here is an example for the
191 Python
<tt>bgl.Graph
</tt> graph type:
194 class count_tree_edges_dijkstra_visitor(bgl.Graph.DijkstraVisitor):
195 def __init__(self, name_map):
196 bgl.Graph.DijkstraVisitor.__init__(self)
197 self.name_map = name_map
199 def edge_relaxed(self, e, g):
200 (u, v) = (g.source(e), g.target(e))
201 print
"Relaxed edge ",
202 print self.name_map[u],
204 print self.name_map[v]
211 <TD nowrap
>Copyright
© 2000-
2001</TD><TD>
212 <A HREF=
"http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek
</A>,
213 Indiana University (
<A
214 HREF=
"mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu
</A>)
<br>
215 <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>
216 <A HREF=
"http://www.osl.iu.edu/~lums">Andrew Lumsdaine
</A>,
217 Indiana University (
<A
218 HREF=
"mailto:lums@osl.iu.edu">lums@osl.iu.edu
</A>)