DijkstraVisitor.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <HTML>
  2. <!--
  3. Copyright (c) Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine 2000
  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: Dijkstra Visitor</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><img src="figs/python.gif" alt="(Python)"/>Dijkstra Visitor Concept</H1>
  16. This concept defines the visitor interface for <a
  17. href="./dijkstra_shortest_paths.html"><tt>dijkstra_shortest_paths()</tt></a>
  18. and related algorithms. The user can create a class that matches this
  19. interface, and then pass objects of the class into
  20. <tt>dijkstra_shortest_paths()</tt> to augment the actions taken during
  21. the search.
  22. <h3>Refinement of</h3>
  23. <a href="../../utility/CopyConstructible.html">Copy Constructible</a>
  24. (copying a visitor should be a lightweight operation).
  25. <h3>Notation</h3>
  26. <Table>
  27. <TR>
  28. <TD><tt>V</tt></TD>
  29. <TD>A type that is a model of Dijkstra Visitor.</TD>
  30. </TR>
  31. <TR>
  32. <TD><tt>vis</tt></TD>
  33. <TD>An object of type <tt>V</tt>.</TD>
  34. </TR>
  35. <TR>
  36. <TD><tt>G</tt></TD>
  37. <TD>A type that is a model of Graph.</TD>
  38. </TR>
  39. <TR>
  40. <TD><tt>g</tt></TD>
  41. <TD>An object of type <tt>G</tt>.</TD>
  42. </TR>
  43. <TR>
  44. <TD><tt>e</tt></TD>
  45. <TD>An object of type <tt>boost::graph_traits&lt;G&gt;::edge_descriptor</tt>.</TD>
  46. </TR>
  47. <TR>
  48. <TD><tt>s,u,v</tt></TD>
  49. <TD>An object of type <tt>boost::graph_traits&lt;G&gt;::vertex_descriptor</tt>.</TD>
  50. </TR>
  51. <TR>
  52. <TD><tt>DistanceMap</tt></TD>
  53. <TD>A type that is a model of <a href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write Property Map</a>.</TD>
  54. </TR>
  55. <TR>
  56. <TD><tt>d</tt></TD>
  57. <TD>An object of type <tt>DistanceMap</tt>.</TD>
  58. </TR>
  59. <TR>
  60. <TD><tt>WeightMap</tt></TD>
  61. <TD>A type that is a model of <a href="../../property_map/doc/ReadWritePropertyMap.html">Readable Property Map</a>.</TD>
  62. </TR>
  63. <TR>
  64. <TD><tt>w</tt></TD>
  65. <TD>An object of type <tt>WeightMap</tt>.</TD>
  66. </TR>
  67. </table>
  68. <h3>Associated Types</h3>
  69. none
  70. <p>
  71. <h3>Valid Expressions</h3>
  72. <table border>
  73. <tr>
  74. <th>Name</th><th>Expression</th><th>Return Type</th><th>Description</th>
  75. </tr>
  76. <tr>
  77. <td>Initialize Vertex</td>
  78. <td><tt>vis.initialize_vertex(u, g)</tt></td>
  79. <td><tt>void</tt></td>
  80. <td>
  81. This is invoked one each vertex of the graph when it is initialized.
  82. </td>
  83. </tr>
  84. <tr>
  85. <td>Examine Vertex</td>
  86. <td><tt>vis.examine_vertex(u, g)</tt></td>
  87. <td><tt>void</tt></td>
  88. <td>
  89. This is invoked on a vertex as it is popped from the queue. This
  90. happens immediately before <tt>examine_edge()</tt> is invoked
  91. on each of the out-edges of vertex <tt>u</tt>.
  92. </td>
  93. </tr>
  94. <tr>
  95. <td>Examine Edge</td>
  96. <td><tt>vis.examine_edge(e, g)</tt></td>
  97. <td><tt>void</tt></td>
  98. <td>
  99. This is invoked on every out-edge of each vertex after it is discovered.
  100. </td>
  101. </tr>
  102. <tr>
  103. <td>Discover Vertex</td>
  104. <td><tt>vis.discover_vertex(u, g)</tt></td>
  105. <td><tt>void</tt></td>
  106. <td>
  107. This is invoked when a vertex is encountered for the first time.
  108. </td>
  109. </tr>
  110. <tr>
  111. <td>Edge Relaxed</td>
  112. <td><tt>vis.edge_relaxed(e, g)</tt></td>
  113. <td><tt>void</tt></td>
  114. <td>
  115. Upon examination, if the following condition holds then the edge
  116. is relaxed (its distance is reduced), and this method is invoked.<br>
  117. <tt>
  118. tie(u,v) = incident(e, g);<br>
  119. D d_u = get(d, u), d_v = get(d, v);<br>
  120. W w_e = get(w, e);<br>
  121. assert(compare(combine(d_u, w_e), d_v));<br>
  122. </tt>
  123. </td>
  124. </tr>
  125. <tr>
  126. <td>Edge Not Relaxed</td>
  127. <td><tt>vis.edge_not_relaxed(e, g)</tt></td>
  128. <td><tt>void</tt></td>
  129. <td>
  130. Upon examination, if the edge is not relaxed (see above) then
  131. this method is invoked.
  132. </td>
  133. </tr>
  134. <tr>
  135. <td>Finish Vertex</td>
  136. <td><tt>vis.finish_vertex(u, g)</tt></td>
  137. <td><tt>void</tt></td>
  138. <td>
  139. This invoked on a vertex after all of its out edges have been added to the
  140. search tree and all of the adjacent vertices have been discovered
  141. (but before their out-edges have been examined).
  142. </td>
  143. </tr>
  144. </table>
  145. <h3>Models</h3>
  146. <ul>
  147. <li><a href="./dijkstra_visitor.html"><tt>dijkstra_visitor</tt></a>
  148. </ul>
  149. <a name="python"></a>
  150. <h3>Python</h3>
  151. To implement a model of the <tt>DijkstraVisitor</tt> concept in Python,
  152. create a new class that derives from the <tt>DijkstraVisitor</tt> type of
  153. the graph, which will be
  154. named <tt><i>GraphType</i>.DijkstraVisitor</tt>. The events and syntax are
  155. the same as with visitors in C++. Here is an example for the
  156. Python <tt>bgl.Graph</tt> graph type:
  157. <pre>
  158. class count_tree_edges_dijkstra_visitor(bgl.Graph.DijkstraVisitor):
  159. def __init__(self, name_map):
  160. bgl.Graph.DijkstraVisitor.__init__(self)
  161. self.name_map = name_map
  162. def edge_relaxed(self, e, g):
  163. (u, v) = (g.source(e), g.target(e))
  164. print "Relaxed edge ",
  165. print self.name_map[u],
  166. print " -> ",
  167. print self.name_map[v]
  168. </pre>
  169. <br>
  170. <HR>
  171. <TABLE>
  172. <TR valign=top>
  173. <TD nowrap>Copyright &copy; 2000-2001</TD><TD>
  174. <A HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</A>,
  175. Indiana University (<A
  176. HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
  177. <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>
  178. <A HREF="https://homes.cs.washington.edu/~al75">Andrew Lumsdaine</A>,
  179. Indiana University (<A
  180. HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)
  181. </TD></TR></TABLE>
  182. </BODY>
  183. </HTML>