astar_search.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. <HTML>
  2. <!--
  3. Copyright (c) 2004 Kris Beevers
  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: A* Heuristic Search</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><A NAME="sec:astar"></A>
  16. <TT>astar_search</TT>
  17. </H1>
  18. <P>
  19. <PRE>
  20. <i>// Named parameter interfaces</i>
  21. template &lt;typename VertexListGraph,
  22. typename AStarHeuristic,
  23. typename P, typename T, typename R&gt;
  24. void
  25. astar_search
  26. (const VertexListGraph &amp;g,
  27. typename graph_traits&lt;VertexListGraph&gt;::vertex_descriptor s,
  28. <a href="AStarHeuristic.html">AStarHeuristic</a> h, const bgl_named_params&lt;P, T, R&gt;&amp; params);
  29. template &lt;typename VertexListGraph,
  30. typename AStarHeuristic,
  31. typename P, typename T, typename R&gt;
  32. void
  33. astar_search_no_init
  34. (const IncidenceGraph &amp;g,
  35. typename graph_traits&lt;VertexListGraph&gt;::vertex_descriptor s,
  36. <a href="AStarHeuristic.html">AStarHeuristic</a> h, const bgl_named_params&lt;P, T, R&gt;&amp; params);
  37. template &lt;typename VertexListGraph,
  38. typename AStarHeuristic,
  39. typename P, typename T, typename R&gt;
  40. void
  41. astar_search_tree
  42. (const VertexListGraph &amp;g,
  43. typename graph_traits&lt;VertexListGraph&gt;::vertex_descriptor s,
  44. <a href="AStarHeuristic.html">AStarHeuristic</a> h, const bgl_named_params&lt;P, T, R&gt;&amp; params);
  45. template &lt;typename VertexListGraph,
  46. typename AStarHeuristic,
  47. typename P, typename T, typename R&gt;
  48. void
  49. astar_search_no_init_tree
  50. (const IncidenceGraph &amp;g,
  51. typename graph_traits&lt;VertexListGraph&gt;::vertex_descriptor s,
  52. <a href="AStarHeuristic.html">AStarHeuristic</a> h, const bgl_named_params&lt;P, T, R&gt;&amp; params);
  53. <i>// Non-named parameter interface</i>
  54. template &lt;typename VertexListGraph, typename AStarHeuristic,
  55. typename <a href="AStarVisitor.html">AStarVisitor</a>, typename PredecessorMap,
  56. typename CostMap, typename DistanceMap,
  57. typename WeightMap, typename VertexIndexMap,
  58. typename ColorMap,
  59. typename <a href="http://www.boost.org/sgi/stl/BinaryPredicate.html">CompareFunction</a>, typename <a href="http://www.boost.org/sgi/stl/BinaryFunction.html">CombineFunction</a>,
  60. typename CostInf, typename CostZero&gt;
  61. inline void
  62. astar_search
  63. (const VertexListGraph &amp;g,
  64. typename graph_traits&lt;VertexListGraph&gt;::vertex_descriptor s,
  65. AStarHeuristic h, AStarVisitor vis,
  66. PredecessorMap predecessor, CostMap cost,
  67. DistanceMap distance, WeightMap weight,
  68. VertexIndexMap index_map, ColorMap color,
  69. CompareFunction compare, CombineFunction combine,
  70. CostInf inf, CostZero zero);
  71. template &lt;typename VertexListGraph, typename AStarHeuristic,
  72. typename <a href="AStarVisitor.html">AStarVisitor</a>, typename PredecessorMap,
  73. typename CostMap, typename DistanceMap,
  74. typename WeightMap,
  75. typename <a href="http://www.boost.org/sgi/stl/BinaryPredicate.html">CompareFunction</a>, typename <a href="http://www.boost.org/sgi/stl/BinaryFunction.html">CombineFunction</a>,
  76. typename CostInf, typename CostZero&gt;
  77. inline void
  78. astar_search_tree
  79. (const VertexListGraph &amp;g,
  80. typename graph_traits&lt;VertexListGraph&gt;::vertex_descriptor s,
  81. AStarHeuristic h, AStarVisitor vis,
  82. PredecessorMap predecessor, CostMap cost,
  83. DistanceMap distance, WeightMap weight,
  84. CompareFunction compare, CombineFunction combine,
  85. CostInf inf, CostZero zero);
  86. <i>// Versions that do not initialize property maps (used for implicit graphs)</i>
  87. template &lt;typename IncidenceGraph, typename AStarHeuristic,
  88. typename <a href="AStarVisitor.html">AStarVisitor</a>, typename PredecessorMap,
  89. typename CostMap, typename DistanceMap,
  90. typename WeightMap, typename ColorMap,
  91. typename VertexIndexMap,
  92. typename <a href="http://www.boost.org/sgi/stl/BinaryPredicate.html">CompareFunction</a>, typename <a href="http://www.boost.org/sgi/stl/BinaryFunction.html">CombineFunction</a>,
  93. typename CostInf, typename CostZero&gt;
  94. inline void
  95. astar_search_no_init
  96. (const IncidenceGraph &amp;g,
  97. typename graph_traits&lt;IncidenceGraph&gt;::vertex_descriptor s,
  98. AStarHeuristic h, AStarVisitor vis,
  99. PredecessorMap predecessor, CostMap cost,
  100. DistanceMap distance, WeightMap weight,
  101. ColorMap color, VertexIndexMap index_map,
  102. CompareFunction compare, CombineFunction combine,
  103. CostInf inf, CostZero zero);
  104. <b>Note that the index_map and color parameters are swapped in
  105. astar_search_no_init() relative to astar_search(); the named parameter
  106. interfaces are not affected.</b>
  107. template &lt;typename IncidenceGraph, typename AStarHeuristic,
  108. typename <a href="AStarVisitor.html">AStarVisitor</a>, typename PredecessorMap,
  109. typename CostMap, typename DistanceMap,
  110. typename WeightMap,
  111. typename <a href="http://www.boost.org/sgi/stl/BinaryPredicate.html">CompareFunction</a>, typename <a href="http://www.boost.org/sgi/stl/BinaryFunction.html">CombineFunction</a>,
  112. typename CostInf, typename CostZero&gt;
  113. inline void
  114. astar_search_no_init_tree
  115. (const IncidenceGraph &amp;g,
  116. typename graph_traits&lt;IncidenceGraph&gt;::vertex_descriptor s,
  117. AStarHeuristic h, AStarVisitor vis,
  118. PredecessorMap predecessor, CostMap cost,
  119. DistanceMap distance, WeightMap weight,
  120. CompareFunction compare, CombineFunction combine,
  121. CostInf inf, CostZero zero);
  122. </PRE>
  123. <P>
  124. This algorithm implements a heuristic search on a weighted, directed
  125. or undirected graph for the case where all edge weights are
  126. non-negative.
  127. </P>
  128. <P>
  129. The A* algorithm is a <i>heuristic graph search algorithm</i>: an A*
  130. search is "guided" by a <i>heuristic function</i>. A heuristic
  131. function <i>h(v)</i> is one which estimates the cost from a non-goal
  132. state (<i>v</i>) in the graph to some goal state, <i>g</i>.
  133. Intuitively, A* follows paths (through the graph) to the goal that are
  134. estimated by the heuristic function to be the best paths. Unlike
  135. best-first search, A* takes into account the known cost from the start
  136. of the search to <i>v</i>; the paths A* takes are guided by a function
  137. <i>f(v) = g(v) + h(v)</i>, where <i>h(v)</i> is the heuristic
  138. function, and <i>g(v)</i> (sometimes denoted <i>c(s, v)</i>) is the
  139. known cost from the start to <i>v</i>. Clearly, the efficiency of A*
  140. is highly dependent on the heuristic function with which it is used.
  141. </P>
  142. <P>
  143. The A* algorithm is very similar to Dijkstra's Shortest Paths
  144. algorithm. This implementation finds all the shortest paths from the
  145. start vertex to every other vertex by creating a search tree,
  146. examining vertices according to their remaining cost to some goal, as
  147. estimated by a heuristic function. Most commonly, A* is used to find
  148. some specific goal vertex or vertices in a graph, after which the
  149. search is terminated.
  150. </P>
  151. <P>
  152. A* is particularly useful for searching <i>implicit</i> graphs.
  153. Implicit graphs are graphs that are not completely known at the
  154. beginning of the search. Upon visiting a vertex, its neighbors are
  155. "generated" and added to the search. Implicit graphs are particularly
  156. useful for searching large state spaces -- in game-playing scenarios
  157. (e.g. chess), for example -- in which it may not be possible to store
  158. the entire graph. Implicit searches can be performed with this
  159. implementation of A* by creating special visitors that generate
  160. neighbors of newly-expanded vertices. Please note that
  161. <tt>astar_search_no_init()</tt> or <tt>astar_search_no_init_tree()</tt> must be
  162. used for implicit graphs; the basic
  163. <tt>astar_search()</tt> function requires a graph that models
  164. the <a href="VertexListGraph.html">Vertex List Graph</a> concept. Both
  165. versions
  166. also require the graph type to model the <a
  167. href="IncidenceGraph.html">Incidence Graph</a> concept.
  168. </P>
  169. <P>
  170. For the non-tree versions of the algorithm,
  171. this implementation of A* is based on an OPEN/CLOSED list formulation.
  172. Vertices on the OPEN list have been ``discovered''
  173. by the algorithm, but not ``expanded'' (we have not discovered their
  174. adjacent vertices). Vertices on the CLOSED list have been completely
  175. examined by our search (we have expanded them and added their children
  176. to the OPEN list). Vertices that are on neither list have not been
  177. encountered in any context so far in our search. A major advantage of
  178. this formulation of the A* algorithm over other approaches is that it
  179. avoids ``cycles'' in the state space; the search will not become
  180. trapped by loops in the graph. The OPEN/CLOSED lists are implemented
  181. using BGL's vertex coloring mechanisms. Vertices in OPEN are colored
  182. gray, vertices in CLOSED are colored black, and undiscovered vertices
  183. are colored white. For the versions of the algorithm whose names end in
  184. <tt>_tree</tt>, all vertices are assumed to always be white, leading to
  185. checking for repeated vertices being done using the distance map. If a dummy
  186. value is used for the distance map and the graph contains cycles, the algorithm
  187. will probably enter an infinite loop.
  188. </P>
  189. <P>
  190. The criteria for expanding a vertex on the OPEN list is that it has
  191. the lowest <i>f(v) = g(v) + h(v)</i> value of all vertices on OPEN.
  192. Cost information about vertices is stored in a property map.
  193. </P>
  194. <P>
  195. The following is the pseudocode for the A* heuristic search algorithm.
  196. In the pseudocode, <i>h</i> is the heuristic function, <i>w</i> is the
  197. edge weight, <i>d</i> is the distance of a vertex from <i>s</i>, and
  198. <i>Q</i> is a priority queue, sorted by <i>f</i>, the estimated cost
  199. to the goal of the path through a vertex. <i>p</i> is a predecessor
  200. map. The visitor event points for the algorithm are indicated by the
  201. labels on the right.
  202. </P>
  203. <table>
  204. <tr>
  205. <td valign="top">
  206. <pre>
  207. A*(<i>G</i>, <i>s</i>, <i>h</i>)
  208. <b>for</b> each vertex <i>u in V</i>
  209. <i>d[u] := f[u] := infinity</i>
  210. <i>color[u] :=</i> WHITE
  211. <i>p[u] := u</i>
  212. <b>end for</b>
  213. <i>color[s] :=</i> GRAY
  214. <i>d[s] := 0</i>
  215. <i>f[s] := h(s)</i>
  216. INSERT(<i>Q, s</i>)
  217. <b>while</b> (<i>Q != &Oslash;</i>)
  218. <i>u :=</i> EXTRACT-MIN(<i>Q</i>)
  219. <b>for</b> each vertex <i>v in Adj[u]</i>
  220. <b>if</b> (<i>w(u,v) + d[u] &lt; d[v]</i>)
  221. <i>d[v] := w(u,v) + d[u]</i>
  222. <i>f[v] := d[v] + h(v)</i>
  223. <i>p[v] := u</i>
  224. <b>if</b> (<i>color[v] =</i> WHITE)
  225. <i>color[v] :=</i> GRAY
  226. INSERT(<i>Q, v</i>)
  227. <b>else if</b> (<i>color[v] =</i> BLACK)
  228. <i>color[v] :=</i> GRAY
  229. INSERT(<i>Q, v</i>)
  230. <b>end if</b>
  231. <b>else</b>
  232. <i>...</i>
  233. <b>end for</b>
  234. <i>color[u] :=</i> BLACK
  235. <b>end while</b>
  236. </pre>
  237. </td>
  238. <td valign="top">
  239. <pre>
  240. initialize vertex <i>u</i>
  241. discover vertex <i>s</i>
  242. examine vertex <i>u</i>
  243. examine edge <i>(u,v)</i>
  244. edge <i>(u,v)</i> relaxed
  245. discover vertex <i>v</i>
  246. reopen vertex <i>v</i>
  247. edge <i>(u,v)</i> not relaxed
  248. finish vertex <i>u</i>
  249. </pre>
  250. </td>
  251. </tr>
  252. </table>
  253. <h3>Where Defined</h3>
  254. <a href="../../../boost/graph/astar_search.hpp"><tt>boost/graph/astar_search.hpp</tt></a>
  255. <h3>Parameters</h3>
  256. IN: <tt>const VertexListGraph&amp; g</tt>
  257. <blockquote>
  258. The graph object on which the algorithm will be applied for <tt>astar_search()</tt>. The type
  259. <tt>VertexListGraph</tt> must be a model of the <a
  260. href="VertexListGraph.html">
  261. Vertex List Graph</a> and <a href="IncidenceGraph.html">Incidence Graph</a>
  262. concepts.
  263. </blockquote>
  264. IN: <tt>const IncidenceGraph&amp; g</tt>
  265. <blockquote>
  266. The graph object on which the algorithm will be applied for <tt>astar_search_no_init()</tt>. The type
  267. <tt>IncidenceGraph</tt> must be a model of the
  268. <a href="IncidenceGraph.html">Incidence Graph</a>
  269. concept.
  270. </blockquote>
  271. IN: <tt>vertex_descriptor s</tt>
  272. <blockquote>
  273. The start vertex for the search. All distances will be calculated
  274. from this vertex, and the shortest paths tree (recorded in the
  275. predecessor map) will be rooted at this vertex.
  276. </blockquote>
  277. IN: <tt>AStarHeuristic h</tt>
  278. <blockquote>
  279. The heuristic function that guides the search. The type
  280. <tt>AStarHeuristic</tt> must be a model of the <a href="AStarHeuristic.html">AStarHeuristic</a>
  281. concept.
  282. </blockquote>
  283. <h3>Named Parameters</h3>
  284. IN: <tt>weight_map(WeightMap w_map)</tt>
  285. <blockquote>
  286. The weight or ``length'' of each edge in the graph. The weights
  287. must all be non-negative; the algorithm will throw a <a
  288. href="./exception.html#negative_edge"><tt>negative_edge</tt></a>
  289. exception if one of the edges is negative. The type
  290. <tt>WeightMap</tt> must be a model of <a
  291. href="../../property_map/doc/ReadablePropertyMap.html"><tt>Readable
  292. Property Map</tt></a>. The edge descriptor type of the graph needs
  293. to be usable as the key type for the weight map. The value type
  294. for this map must be the same as the value type of the distance
  295. map.<br>
  296. <b>Default:</b> <tt>get(edge\_weight, g)</tt>
  297. </blockquote>
  298. IN: <tt>vertex_index_map(VertexIndexMap i_map)</tt>
  299. <blockquote>
  300. This maps each vertex to an integer in the range <tt>[0,
  301. num_vertices(g))</tt>. This is necessary in non-tree versions of the
  302. algorithm for efficient updates of
  303. the heap data structure when an edge is relaxed. The type
  304. <tt>VertexIndexMap</tt> must be a model of <a
  305. href="../../property_map/doc/ReadablePropertyMap.html"><tt>Readable
  306. Property Map</tt></a>. The value type of the map must be an integer
  307. type. The vertex descriptor type of the graph needs to be usable as
  308. the key type of the map.<br>
  309. <b>Default:</b> <tt>get(vertex_index, g)</tt>.
  310. Note: if you use this default, make sure your graph has
  311. an internal <tt>vertex_index</tt> property. For example,
  312. <tt>adjacency_list</tt> with <tt>VertexList=listS</tt> does
  313. not have an internal <tt>vertex_index</tt> property.
  314. </blockquote>
  315. OUT: <tt>predecessor_map(PredecessorMap p_map)</tt>
  316. <blockquote>
  317. The predecessor map records the edges in the minimum spanning tree.
  318. Upon completion of the algorithm, the edges <tt>(p[u],u)</tt> for
  319. all <tt>u</tt> in <tt>V</tt> are in the minimum spanning tree. If
  320. <tt>p[u] = u</tt> then <tt>u</tt> is either the start vertex or a
  321. vertex that is not reachable from the start. The
  322. <tt>PredecessorMap</tt> type must be a <a
  323. href="../../property_map/doc/ReadWritePropertyMap.html"><tt>Read/Write
  324. Property Map</tt></a> with key and vertex types the same as the
  325. vertex descriptor type of the graph.<br>
  326. <b>Default:</b> <tt>dummy_property_map</tt>
  327. </blockquote>
  328. UTIL/OUT: <tt>distance_map(DistanceMap d_map)</tt>
  329. <blockquote>
  330. The shortest path weight from the start vertex <tt>s</tt> to each
  331. vertex in the graph <tt>g</tt> is recorded in this property map.
  332. The shortest path weight is the sum of the edge weights along the
  333. shortest path. The type <tt>DistanceMap</tt> must be a model of <a
  334. href="../../property_map/doc/ReadWritePropertyMap.html"><tt>Read/Write
  335. Property Map</tt></a>. The vertex descriptor type of the graph
  336. needs to be usable as the key type of the distance map. The value
  337. type of the distance map is the element type of a <a
  338. href="./Monoid.html"><tt>Monoid</tt></a> formed with the
  339. <tt>combine</tt> function object and the zero object for the
  340. identity element. Also the distance value type must have a <a
  341. href="http://www.boost.org/sgi/stl/StrictWeakOrdering.html"><tt>StrictWeakOrdering</tt></a>
  342. provided by the <tt>compare</tt> function object. A
  343. <tt>constant_writable_property_map</tt> returning the infinity value can be
  344. used for this parameter in tree versions of the algorithm when the graph does
  345. not contain a directed cycle.<br>
  346. <b>Default:</b> <tt>shared_array_property_map</tt>
  347. with the same value type as the
  348. <tt>WeightMap</tt>, and of size <tt>num_vertices(g)</tt>, and using
  349. the <tt>i_map</tt> for the index map.
  350. </blockquote>
  351. UTIL/OUT: <tt>rank_map(CostMap c_map)</tt>
  352. <blockquote>
  353. The <i>f</i>-value for each vertex. The <i>f</i>-value is defined
  354. as the sum of the cost to get to a vertex from the start vertex, and
  355. the estimated cost (as returned by the heuristic function
  356. <tt>h</tt>) from the vertex to a goal. The type <tt>CostMap</tt>
  357. must be a model of <a
  358. href="../../property_map/doc/ReadWritePropertyMap.html"><tt>Read/Write
  359. Property Map</tt></a> in non-tree versions of the algorithm, and <a
  360. href="../../property_map/doc/WritablePropertyMap.html"><tt>Writable Property
  361. Map</tt></a> in tree versions of the algorithm. The vertex descriptor type
  362. of the graph
  363. needs to be usable as the key type of the distance map. The value
  364. type of the distance map is the element type of a <a
  365. href="./Monoid.html"><tt>Monoid</tt></a> formed with the
  366. <tt>combine</tt> function object and the zero object for the
  367. identity element. Also the distance value type must have a <a
  368. href="http://www.boost.org/sgi/stl/StrictWeakOrdering.html"><tt>StrictWeakOrdering</tt></a>
  369. provided by the <tt>compare</tt> function object. The value type
  370. for this map must be the same as the value type for the distance
  371. map. In tree versions of the algorithm, <tt>null_property_map</tt> can be
  372. used for this parameter.<br>
  373. <b>Default:</b> <tt>shared_array_property_map</tt>
  374. with the same value type as the
  375. <tt>DistanceMap</tt>, and of size <tt>num_vertices(g)</tt>, and using
  376. the <tt>i_map</tt> for the index map.
  377. </blockquote>
  378. UTIL/OUT: <tt>color_map(ColorMap c_map)</tt>
  379. <blockquote>
  380. This is used during the execution of non-tree versions of the algorithm to
  381. mark the
  382. vertices, indicating whether they are on the OPEN or CLOSED lists.
  383. The vertices start out white and become gray when they are inserted
  384. into the OPEN list. They then turn black when they are examined and
  385. placed on the CLOSED list. At the end of the algorithm, vertices
  386. reachable from the source vertex will have been colored black. All
  387. other vertices will still be white. The type <tt>ColorMap</tt> must
  388. be a model of <a
  389. href="../../property_map/doc/ReadWritePropertyMap.html"><tt>Read/Write
  390. Property Map</tt></a>. A vertex descriptor must be usable as the
  391. key type of the map, and the value type of the map must be a model
  392. of <a href="./ColorValue.html"><tt>Color Value</tt></a>.<br>
  393. <b>Default:</b> <tt>shared_array_property_map</tt>
  394. of value type <tt>default_color_type</tt>, with size
  395. <tt>num_vertices(g)</tt>, and using
  396. the <tt>i_map</tt> for the index map.
  397. </blockquote>
  398. IN: <tt>distance_compare(CompareFunction cmp)</tt>
  399. <blockquote>
  400. This function is use to compare distances to determine which vertex
  401. is closer to the start vertex, and to compare <i>f</i>-values to
  402. determine which vertex on the OPEN list to examine next. The
  403. <tt>CompareFunction</tt> type must be a model of <a
  404. href="http://www.boost.org/sgi/stl/BinaryPredicate.html"><tt>Binary
  405. Predicate</tt></a> and have argument types that match the value type
  406. of the <tt>DistanceMap</tt> property map.<br>
  407. <b>Default:</b> <tt>std::less&lt;D&gt;</tt> with <tt>D = typename
  408. property_traits&lt;DistanceMap&gt;::value_type</tt>.
  409. </blockquote>
  410. IN: <tt>distance_combine(CombineFunction cmb)</tt>
  411. <blockquote>
  412. This function is used to combine distances to compute the distance
  413. of a path, and to combine distance and heuristic values to compute
  414. the <i>f</i>-value of a vertex. The <tt>CombineFunction</tt> type
  415. must be a model of <a
  416. href="http://www.boost.org/sgi/stl/BinaryFunction.html"><tt>Binary
  417. Function</tt></a>. Both argument types of the binary function must
  418. match the value type of the <tt>DistanceMap</tt> property map (which
  419. is the same as that of the <tt>WeightMap</tt> and <tt>CostMap</tt>
  420. property maps). The result type must be the same type as the
  421. distance value type.<br>
  422. <b>Default:</b> <tt>std::plus&lt;D&gt;</tt> with <tt>D = typename
  423. property_traits&lt;DistanceMap&gt;::value_type</tt>.
  424. </blockquote>
  425. IN: <tt>distance_inf(D inf)</tt>
  426. <blockquote>
  427. The <tt>inf</tt> object must be the greatest value of any <tt>D</tt>
  428. object. That is, <tt>compare(d, inf) == true</tt> for any <tt>d !=
  429. inf</tt>. The type <tt>D</tt> is the value type of the
  430. <tt>DistanceMap</tt>.<br>
  431. <b>Default:</b> <tt>std::numeric_limits&lt;D&gt;::max()</tt>
  432. </blockquote>
  433. IN: <tt>distance_zero(D zero)</tt>
  434. <blockquote>
  435. The <tt>zero</tt> value must be the identity element for the <a
  436. href="./Monoid.html"><tt>Monoid</tt></a> formed by the distance
  437. values and the <tt>combine</tt> function object. The type
  438. <tt>D</tt> is the value type of the <tt>DistanceMap</tt>.<br>
  439. <b>Default</b>: <tt>D()</tt> with <tt>D = typename
  440. property_traits&lt;DistanceMap&gt;::value_type</tt>.
  441. </blockquote>
  442. OUT: <tt>visitor(AStarVisitor v)</tt>
  443. <blockquote>
  444. Use this to specify actions that you would like to happen during
  445. certain event points within the algorithm. The type
  446. <tt>AStarVisitor</tt> must be a model of the <a
  447. href="AStarVisitor.html"><tt>AStarVisitor</tt></a> concept. The
  448. visitor object is passed by value <a href="#1">[1]</a>.<br>
  449. <b>Default:</b> <tt>astar_visitor&lt;null_visitor&gt;</tt>
  450. </blockquote>
  451. <H3>Complexity</H3>
  452. <P>
  453. The time complexity is <i>O((E + V) log V)</i>.
  454. <h3>Visitor Event Points</h3>
  455. <ul>
  456. <li><b><tt>vis.initialize_vertex(u, g)</tt></b>
  457. is invoked on each vertex in the graph before the start of the
  458. algorithm.
  459. <li><b><tt>vis.discover_vertex(v, g)</tt></b>
  460. is invoked when a vertex is first discovered and is added to the
  461. OPEN list.
  462. <li><b><tt>vis.examine_vertex(u, g)</tt></b>
  463. is invoked when a vertex is popped from
  464. the queue (i.e., it has the lowest cost on the OPEN list).
  465. <li><b><tt>vis.examine_edge(e, g)</tt></b>
  466. is invoked on each out-edge of a vertex immediately after it is
  467. examined.
  468. <li><b><tt>vis.edge_relaxed(e, g)</tt></b>
  469. is invoked on edge <i>(u,v)</i> if <i>d[u] + w(u,v) &lt; d[v]</i>.
  470. <li><b><tt>vis.edge_not_relaxed(e, g)</tt></b>
  471. is invoked if the edge is not relaxed (see above).
  472. <li><b><tt>vis.black_target(e, g)</tt></b>
  473. is invoked when a vertex that is on the CLOSED list is
  474. "rediscovered" via a more efficient path, and is re-added to the
  475. OPEN list.
  476. <li><b><tt>vis.finish_vertex(u, g)</tt></b>
  477. is invoked on a vertex when it is added to the CLOSED list, which
  478. happens after all of its out edges have been examined.
  479. </ul>
  480. <H3>Example</H3>
  481. <P>
  482. See <a href="../example/astar-cities.cpp">
  483. <TT>example/astar-cities.cpp</TT></a> for an example of
  484. using A* search.
  485. <H3>Notes</H3>
  486. <a name="1">[1]</a> Since the visitor parameter is passed by value, if
  487. your visitor contains state then any changes to the state during the
  488. algorithm will be made to a copy of the visitor object, not the
  489. visitor object passed in. Therefore you may want the visitor to hold
  490. this state by pointer or reference.
  491. <br>
  492. <HR>
  493. <TABLE>
  494. <TR valign=top>
  495. <TD nowrap>Copyright &copy; 2004</TD><TD>
  496. <A HREF="http://cs.krisbeevers.com/">Kristopher Beevers</A>,
  497. Rensselaer Polytechnic Institute (<A
  498. HREF="mailto:beevek@cs.rpi.edu">beevek@cs.rpi.edu</A>)
  499. </TD></TR></TABLE>
  500. </BODY>
  501. </HTML>