astar_search.hpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. //
  2. //=======================================================================
  3. // Copyright (c) 2004 Kristopher Beevers
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //=======================================================================
  9. //
  10. #ifndef BOOST_GRAPH_ASTAR_SEARCH_HPP
  11. #define BOOST_GRAPH_ASTAR_SEARCH_HPP
  12. #include <functional>
  13. #include <vector>
  14. #include <boost/limits.hpp>
  15. #include <boost/throw_exception.hpp>
  16. #include <boost/graph/named_function_params.hpp>
  17. #include <boost/graph/relax.hpp>
  18. #include <boost/graph/exception.hpp>
  19. #include <boost/graph/breadth_first_search.hpp>
  20. #include <boost/graph/iteration_macros.hpp>
  21. #include <boost/graph/detail/d_ary_heap.hpp>
  22. #include <boost/graph/property_maps/constant_property_map.hpp>
  23. #include <boost/property_map/property_map.hpp>
  24. #include <boost/property_map/vector_property_map.hpp>
  25. #include <boost/property_map/function_property_map.hpp>
  26. #include <boost/concept/assert.hpp>
  27. namespace boost {
  28. template <class Heuristic, class Graph>
  29. struct AStarHeuristicConcept {
  30. void constraints()
  31. {
  32. BOOST_CONCEPT_ASSERT(( CopyConstructibleConcept<Heuristic> ));
  33. h(u);
  34. }
  35. Heuristic h;
  36. typename graph_traits<Graph>::vertex_descriptor u;
  37. };
  38. template <class Graph, class CostType>
  39. class astar_heuristic
  40. {
  41. public:
  42. typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
  43. typedef Vertex argument_type;
  44. typedef CostType result_type;
  45. astar_heuristic() {}
  46. CostType operator()(Vertex u) { return static_cast<CostType>(0); }
  47. };
  48. template <class Visitor, class Graph>
  49. struct AStarVisitorConcept {
  50. void constraints()
  51. {
  52. BOOST_CONCEPT_ASSERT(( CopyConstructibleConcept<Visitor> ));
  53. vis.initialize_vertex(u, g);
  54. vis.discover_vertex(u, g);
  55. vis.examine_vertex(u, g);
  56. vis.examine_edge(e, g);
  57. vis.edge_relaxed(e, g);
  58. vis.edge_not_relaxed(e, g);
  59. vis.black_target(e, g);
  60. vis.finish_vertex(u, g);
  61. }
  62. Visitor vis;
  63. Graph g;
  64. typename graph_traits<Graph>::vertex_descriptor u;
  65. typename graph_traits<Graph>::edge_descriptor e;
  66. };
  67. template <class Visitors = null_visitor>
  68. class astar_visitor : public bfs_visitor<Visitors> {
  69. public:
  70. astar_visitor() {}
  71. astar_visitor(Visitors vis)
  72. : bfs_visitor<Visitors>(vis) {}
  73. template <class Edge, class Graph>
  74. void edge_relaxed(Edge e, const Graph& g) {
  75. invoke_visitors(this->m_vis, e, g, on_edge_relaxed());
  76. }
  77. template <class Edge, class Graph>
  78. void edge_not_relaxed(Edge e, const Graph& g) {
  79. invoke_visitors(this->m_vis, e, g, on_edge_not_relaxed());
  80. }
  81. private:
  82. template <class Edge, class Graph>
  83. void tree_edge(Edge e, const Graph& g) {}
  84. template <class Edge, class Graph>
  85. void non_tree_edge(Edge e, const Graph& g) {}
  86. };
  87. template <class Visitors>
  88. astar_visitor<Visitors>
  89. make_astar_visitor(Visitors vis) {
  90. return astar_visitor<Visitors>(vis);
  91. }
  92. typedef astar_visitor<> default_astar_visitor;
  93. namespace detail {
  94. template <class AStarHeuristic, class UniformCostVisitor,
  95. class UpdatableQueue, class PredecessorMap,
  96. class CostMap, class DistanceMap, class WeightMap,
  97. class ColorMap, class BinaryFunction,
  98. class BinaryPredicate>
  99. struct astar_bfs_visitor
  100. {
  101. typedef typename property_traits<CostMap>::value_type C;
  102. typedef typename property_traits<ColorMap>::value_type ColorValue;
  103. typedef color_traits<ColorValue> Color;
  104. typedef typename property_traits<DistanceMap>::value_type distance_type;
  105. astar_bfs_visitor(AStarHeuristic h, UniformCostVisitor vis,
  106. UpdatableQueue& Q, PredecessorMap p,
  107. CostMap c, DistanceMap d, WeightMap w,
  108. ColorMap col, BinaryFunction combine,
  109. BinaryPredicate compare, C zero)
  110. : m_h(h), m_vis(vis), m_Q(Q), m_predecessor(p), m_cost(c),
  111. m_distance(d), m_weight(w), m_color(col),
  112. m_combine(combine), m_compare(compare), m_zero(zero) {}
  113. template <class Vertex, class Graph>
  114. void initialize_vertex(Vertex u, const Graph& g) {
  115. m_vis.initialize_vertex(u, g);
  116. }
  117. template <class Vertex, class Graph>
  118. void discover_vertex(Vertex u, const Graph& g) {
  119. m_vis.discover_vertex(u, g);
  120. }
  121. template <class Vertex, class Graph>
  122. void examine_vertex(Vertex u, const Graph& g) {
  123. m_vis.examine_vertex(u, g);
  124. }
  125. template <class Vertex, class Graph>
  126. void finish_vertex(Vertex u, const Graph& g) {
  127. m_vis.finish_vertex(u, g);
  128. }
  129. template <class Edge, class Graph>
  130. void examine_edge(Edge e, const Graph& g) {
  131. if (m_compare(get(m_weight, e), m_zero))
  132. BOOST_THROW_EXCEPTION(negative_edge());
  133. m_vis.examine_edge(e, g);
  134. }
  135. template <class Edge, class Graph>
  136. void non_tree_edge(Edge, const Graph&) {}
  137. template <class Edge, class Graph>
  138. void tree_edge(Edge e, const Graph& g) {
  139. using boost::get;
  140. bool m_decreased =
  141. relax(e, g, m_weight, m_predecessor, m_distance,
  142. m_combine, m_compare);
  143. if(m_decreased) {
  144. m_vis.edge_relaxed(e, g);
  145. put(m_cost, target(e, g),
  146. m_combine(get(m_distance, target(e, g)),
  147. m_h(target(e, g))));
  148. } else
  149. m_vis.edge_not_relaxed(e, g);
  150. }
  151. template <class Edge, class Graph>
  152. void gray_target(Edge e, const Graph& g) {
  153. using boost::get;
  154. bool m_decreased =
  155. relax(e, g, m_weight, m_predecessor, m_distance,
  156. m_combine, m_compare);
  157. if(m_decreased) {
  158. put(m_cost, target(e, g),
  159. m_combine(get(m_distance, target(e, g)),
  160. m_h(target(e, g))));
  161. m_Q.update(target(e, g));
  162. m_vis.edge_relaxed(e, g);
  163. } else
  164. m_vis.edge_not_relaxed(e, g);
  165. }
  166. template <class Edge, class Graph>
  167. void black_target(Edge e, const Graph& g) {
  168. using boost::get;
  169. bool m_decreased =
  170. relax(e, g, m_weight, m_predecessor, m_distance,
  171. m_combine, m_compare);
  172. if(m_decreased) {
  173. m_vis.edge_relaxed(e, g);
  174. put(m_cost, target(e, g),
  175. m_combine(get(m_distance, target(e, g)),
  176. m_h(target(e, g))));
  177. m_Q.push(target(e, g));
  178. put(m_color, target(e, g), Color::gray());
  179. m_vis.black_target(e, g);
  180. } else
  181. m_vis.edge_not_relaxed(e, g);
  182. }
  183. AStarHeuristic m_h;
  184. UniformCostVisitor m_vis;
  185. UpdatableQueue& m_Q;
  186. PredecessorMap m_predecessor;
  187. CostMap m_cost;
  188. DistanceMap m_distance;
  189. WeightMap m_weight;
  190. ColorMap m_color;
  191. BinaryFunction m_combine;
  192. BinaryPredicate m_compare;
  193. C m_zero;
  194. };
  195. } // namespace detail
  196. template <typename VertexListGraph, typename AStarHeuristic,
  197. typename AStarVisitor, typename PredecessorMap,
  198. typename CostMap, typename DistanceMap,
  199. typename WeightMap, typename ColorMap,
  200. typename VertexIndexMap,
  201. typename CompareFunction, typename CombineFunction,
  202. typename CostInf, typename CostZero>
  203. inline void
  204. astar_search_no_init
  205. (const VertexListGraph &g,
  206. typename graph_traits<VertexListGraph>::vertex_descriptor s,
  207. AStarHeuristic h, AStarVisitor vis,
  208. PredecessorMap predecessor, CostMap cost,
  209. DistanceMap distance, WeightMap weight,
  210. ColorMap color, VertexIndexMap index_map,
  211. CompareFunction compare, CombineFunction combine,
  212. CostInf /*inf*/, CostZero zero)
  213. {
  214. typedef typename graph_traits<VertexListGraph>::vertex_descriptor
  215. Vertex;
  216. typedef boost::vector_property_map<std::size_t, VertexIndexMap> IndexInHeapMap;
  217. IndexInHeapMap index_in_heap(index_map);
  218. typedef d_ary_heap_indirect<Vertex, 4, IndexInHeapMap, CostMap, CompareFunction>
  219. MutableQueue;
  220. MutableQueue Q(cost, index_in_heap, compare);
  221. detail::astar_bfs_visitor<AStarHeuristic, AStarVisitor,
  222. MutableQueue, PredecessorMap, CostMap, DistanceMap,
  223. WeightMap, ColorMap, CombineFunction, CompareFunction>
  224. bfs_vis(h, vis, Q, predecessor, cost, distance, weight,
  225. color, combine, compare, zero);
  226. breadth_first_visit(g, s, Q, bfs_vis, color);
  227. }
  228. namespace graph_detail {
  229. template <typename A, typename B>
  230. struct select1st {
  231. typedef std::pair<A, B> argument_type;
  232. typedef A result_type;
  233. A operator()(const std::pair<A, B>& p) const {return p.first;}
  234. };
  235. }
  236. template <typename VertexListGraph, typename AStarHeuristic,
  237. typename AStarVisitor, typename PredecessorMap,
  238. typename CostMap, typename DistanceMap,
  239. typename WeightMap,
  240. typename CompareFunction, typename CombineFunction,
  241. typename CostInf, typename CostZero>
  242. inline void
  243. astar_search_no_init_tree
  244. (const VertexListGraph &g,
  245. typename graph_traits<VertexListGraph>::vertex_descriptor s,
  246. AStarHeuristic h, AStarVisitor vis,
  247. PredecessorMap predecessor, CostMap cost,
  248. DistanceMap distance, WeightMap weight,
  249. CompareFunction compare, CombineFunction combine,
  250. CostInf /*inf*/, CostZero zero)
  251. {
  252. typedef typename graph_traits<VertexListGraph>::vertex_descriptor
  253. Vertex;
  254. typedef typename property_traits<DistanceMap>::value_type Distance;
  255. typedef d_ary_heap_indirect<
  256. std::pair<Distance, Vertex>,
  257. 4,
  258. null_property_map<std::pair<Distance, Vertex>, std::size_t>,
  259. function_property_map<graph_detail::select1st<Distance, Vertex>, std::pair<Distance, Vertex> >,
  260. CompareFunction>
  261. MutableQueue;
  262. MutableQueue Q(
  263. make_function_property_map<std::pair<Distance, Vertex> >(graph_detail::select1st<Distance, Vertex>()),
  264. null_property_map<std::pair<Distance, Vertex>, std::size_t>(),
  265. compare);
  266. vis.discover_vertex(s, g);
  267. Q.push(std::make_pair(get(cost, s), s));
  268. while (!Q.empty()) {
  269. Vertex v;
  270. Distance v_rank;
  271. boost::tie(v_rank, v) = Q.top();
  272. Q.pop();
  273. vis.examine_vertex(v, g);
  274. BGL_FORALL_OUTEDGES_T(v, e, g, VertexListGraph) {
  275. Vertex w = target(e, g);
  276. vis.examine_edge(e, g);
  277. Distance e_weight = get(weight, e);
  278. if (compare(e_weight, zero))
  279. BOOST_THROW_EXCEPTION(negative_edge());
  280. bool decreased =
  281. relax(e, g, weight, predecessor, distance,
  282. combine, compare);
  283. combine(get(distance, v), e_weight);
  284. if (decreased) {
  285. vis.edge_relaxed(e, g);
  286. Distance w_rank = combine(get(distance, w), h(w));
  287. put(cost, w, w_rank);
  288. vis.discover_vertex(w, g);
  289. Q.push(std::make_pair(w_rank, w));
  290. } else {
  291. vis.edge_not_relaxed(e, g);
  292. }
  293. }
  294. vis.finish_vertex(v, g);
  295. }
  296. }
  297. // Non-named parameter interface
  298. template <typename VertexListGraph, typename AStarHeuristic,
  299. typename AStarVisitor, typename PredecessorMap,
  300. typename CostMap, typename DistanceMap,
  301. typename WeightMap, typename VertexIndexMap,
  302. typename ColorMap,
  303. typename CompareFunction, typename CombineFunction,
  304. typename CostInf, typename CostZero>
  305. inline void
  306. astar_search
  307. (const VertexListGraph &g,
  308. typename graph_traits<VertexListGraph>::vertex_descriptor s,
  309. AStarHeuristic h, AStarVisitor vis,
  310. PredecessorMap predecessor, CostMap cost,
  311. DistanceMap distance, WeightMap weight,
  312. VertexIndexMap index_map, ColorMap color,
  313. CompareFunction compare, CombineFunction combine,
  314. CostInf inf, CostZero zero)
  315. {
  316. typedef typename property_traits<ColorMap>::value_type ColorValue;
  317. typedef color_traits<ColorValue> Color;
  318. typename graph_traits<VertexListGraph>::vertex_iterator ui, ui_end;
  319. for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) {
  320. put(color, *ui, Color::white());
  321. put(distance, *ui, inf);
  322. put(cost, *ui, inf);
  323. put(predecessor, *ui, *ui);
  324. vis.initialize_vertex(*ui, g);
  325. }
  326. put(distance, s, zero);
  327. put(cost, s, h(s));
  328. astar_search_no_init
  329. (g, s, h, vis, predecessor, cost, distance, weight,
  330. color, index_map, compare, combine, inf, zero);
  331. }
  332. // Non-named parameter interface
  333. template <typename VertexListGraph, typename AStarHeuristic,
  334. typename AStarVisitor, typename PredecessorMap,
  335. typename CostMap, typename DistanceMap,
  336. typename WeightMap,
  337. typename CompareFunction, typename CombineFunction,
  338. typename CostInf, typename CostZero>
  339. inline void
  340. astar_search_tree
  341. (const VertexListGraph &g,
  342. typename graph_traits<VertexListGraph>::vertex_descriptor s,
  343. AStarHeuristic h, AStarVisitor vis,
  344. PredecessorMap predecessor, CostMap cost,
  345. DistanceMap distance, WeightMap weight,
  346. CompareFunction compare, CombineFunction combine,
  347. CostInf inf, CostZero zero)
  348. {
  349. typename graph_traits<VertexListGraph>::vertex_iterator ui, ui_end;
  350. for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) {
  351. put(distance, *ui, inf);
  352. put(cost, *ui, inf);
  353. put(predecessor, *ui, *ui);
  354. vis.initialize_vertex(*ui, g);
  355. }
  356. put(distance, s, zero);
  357. put(cost, s, h(s));
  358. astar_search_no_init_tree
  359. (g, s, h, vis, predecessor, cost, distance, weight,
  360. compare, combine, inf, zero);
  361. }
  362. // Named parameter interfaces
  363. template <typename VertexListGraph,
  364. typename AStarHeuristic,
  365. typename P, typename T, typename R>
  366. void
  367. astar_search
  368. (const VertexListGraph &g,
  369. typename graph_traits<VertexListGraph>::vertex_descriptor s,
  370. AStarHeuristic h, const bgl_named_params<P, T, R>& params)
  371. {
  372. using namespace boost::graph::keywords;
  373. typedef bgl_named_params<P, T, R> params_type;
  374. BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(params_type, params)
  375. // Distance type is the value type of the distance map if there is one,
  376. // otherwise the value type of the weight map.
  377. typedef typename boost::detail::override_const_property_result<
  378. arg_pack_type,
  379. boost::graph::keywords::tag::weight_map,
  380. edge_weight_t,
  381. VertexListGraph
  382. >::type weight_map_type;
  383. typedef typename boost::property_traits<weight_map_type>::value_type D;
  384. const D inf = arg_pack[_distance_inf || detail::get_max<D>()];
  385. const D zero_actual = D();
  386. const D zero_d = arg_pack[_distance_zero | zero_actual];
  387. null_visitor null_vis;
  388. astar_visitor<null_visitor> default_visitor(null_vis);
  389. typename boost::parameter::binding<
  390. arg_pack_type,
  391. boost::graph::keywords::tag::visitor,
  392. dummy_property_map&
  393. >::type vis = arg_pack[_visitor | default_visitor];
  394. dummy_property_map dummy_prop;
  395. typename boost::parameter::binding<
  396. arg_pack_type,
  397. boost::graph::keywords::tag::predecessor_map,
  398. dummy_property_map&
  399. >::type pred_map = arg_pack[_predecessor_map | dummy_prop];
  400. boost::detail::make_property_map_from_arg_pack_gen<
  401. boost::graph::keywords::tag::rank_map,
  402. D
  403. > rank_map_gen(zero_actual);
  404. typename boost::detail::map_maker<
  405. VertexListGraph,
  406. arg_pack_type,
  407. boost::graph::keywords::tag::rank_map,
  408. D
  409. >::map_type r_map = rank_map_gen(g, arg_pack);
  410. boost::detail::make_property_map_from_arg_pack_gen<
  411. boost::graph::keywords::tag::distance_map,
  412. D
  413. > dist_map_gen(zero_actual);
  414. typename boost::detail::map_maker<
  415. VertexListGraph,
  416. arg_pack_type,
  417. boost::graph::keywords::tag::distance_map,
  418. D
  419. >::map_type dist_map = dist_map_gen(g, arg_pack);
  420. weight_map_type w_map = detail::override_const_property(arg_pack, _weight_map, g, edge_weight);
  421. typename boost::detail::override_const_property_result<
  422. arg_pack_type,
  423. boost::graph::keywords::tag::vertex_index_map,
  424. vertex_index_t,
  425. VertexListGraph
  426. >::type v_i_map = detail::override_const_property(arg_pack, _vertex_index_map, g, vertex_index);
  427. typename boost::detail::map_maker<
  428. VertexListGraph,
  429. arg_pack_type,
  430. boost::graph::keywords::tag::color_map,
  431. boost::default_color_type
  432. >::map_type c_map = boost::detail::make_color_map_from_arg_pack(g, arg_pack);
  433. std::less<D> default_compare;
  434. typename boost::parameter::binding<
  435. arg_pack_type,
  436. boost::graph::keywords::tag::distance_compare,
  437. std::less<D>&
  438. >::type dist_comp = arg_pack[_distance_compare | default_compare];
  439. closed_plus<D> default_combine(inf);
  440. typename boost::parameter::binding<
  441. arg_pack_type,
  442. boost::graph::keywords::tag::distance_combine,
  443. closed_plus<D>&
  444. >::type dist_comb = arg_pack[_distance_combine | default_combine];
  445. astar_search
  446. (g, s, h,
  447. vis,
  448. pred_map,
  449. r_map,
  450. dist_map,
  451. w_map,
  452. v_i_map,
  453. c_map,
  454. dist_comp,
  455. dist_comb,
  456. inf,
  457. zero_d);
  458. }
  459. template <typename VertexListGraph,
  460. typename AStarHeuristic,
  461. typename P, typename T, typename R>
  462. void
  463. astar_search_tree
  464. (const VertexListGraph &g,
  465. typename graph_traits<VertexListGraph>::vertex_descriptor s,
  466. AStarHeuristic h, const bgl_named_params<P, T, R>& params)
  467. {
  468. using namespace boost::graph::keywords;
  469. typedef bgl_named_params<P, T, R> params_type;
  470. BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(params_type, params)
  471. // Distance type is the value type of the distance map if there is one,
  472. // otherwise the value type of the weight map.
  473. typedef typename boost::detail::override_const_property_result<
  474. arg_pack_type,
  475. boost::graph::keywords::tag::weight_map,
  476. edge_weight_t,
  477. VertexListGraph
  478. >::type weight_map_type;
  479. typedef typename boost::property_traits<weight_map_type>::value_type D;
  480. const D inf = arg_pack[_distance_inf || detail::get_max<D>()];
  481. const D zero_actual = D();
  482. const D zero_d = arg_pack[_distance_zero | zero_actual];
  483. null_visitor null_vis;
  484. astar_visitor<null_visitor> default_visitor(null_vis);
  485. typename boost::parameter::binding<
  486. arg_pack_type,
  487. boost::graph::keywords::tag::visitor,
  488. dummy_property_map&
  489. >::type vis = arg_pack[_visitor | default_visitor];
  490. dummy_property_map dummy_prop;
  491. typename boost::parameter::binding<
  492. arg_pack_type,
  493. boost::graph::keywords::tag::predecessor_map,
  494. dummy_property_map&
  495. >::type pred_map = arg_pack[_predecessor_map | dummy_prop];
  496. boost::detail::make_property_map_from_arg_pack_gen<
  497. boost::graph::keywords::tag::rank_map,
  498. D
  499. > rank_map_gen(zero_actual);
  500. typename boost::detail::map_maker<
  501. VertexListGraph,
  502. arg_pack_type,
  503. boost::graph::keywords::tag::rank_map,
  504. D
  505. >::map_type r_map = rank_map_gen(g, arg_pack);
  506. boost::detail::make_property_map_from_arg_pack_gen<
  507. boost::graph::keywords::tag::distance_map,
  508. D
  509. > dist_map_gen(zero_actual);
  510. typename boost::detail::map_maker<
  511. VertexListGraph,
  512. arg_pack_type,
  513. boost::graph::keywords::tag::distance_map,
  514. D
  515. >::map_type dist_map = dist_map_gen(g, arg_pack);
  516. weight_map_type w_map = detail::override_const_property(arg_pack, _weight_map, g, edge_weight);
  517. std::less<D> default_compare;
  518. typename boost::parameter::binding<
  519. arg_pack_type,
  520. boost::graph::keywords::tag::distance_compare,
  521. std::less<D>&
  522. >::type dist_comp = arg_pack[_distance_compare | default_compare];
  523. closed_plus<D> default_combine(inf);
  524. typename boost::parameter::binding<
  525. arg_pack_type,
  526. boost::graph::keywords::tag::distance_combine,
  527. closed_plus<D>&
  528. >::type dist_comb = arg_pack[_distance_combine | default_combine];
  529. astar_search_tree
  530. (g, s, h,
  531. vis,
  532. pred_map,
  533. r_map,
  534. dist_map,
  535. w_map,
  536. dist_comp,
  537. dist_comb,
  538. inf,
  539. zero_d);
  540. }
  541. template <typename VertexListGraph,
  542. typename AStarHeuristic,
  543. typename P, typename T, typename R>
  544. void
  545. astar_search_no_init
  546. (const VertexListGraph &g,
  547. typename graph_traits<VertexListGraph>::vertex_descriptor s,
  548. AStarHeuristic h, const bgl_named_params<P, T, R>& params)
  549. {
  550. using namespace boost::graph::keywords;
  551. typedef bgl_named_params<P, T, R> params_type;
  552. BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(params_type, params)
  553. typedef typename boost::detail::override_const_property_result<
  554. arg_pack_type,
  555. boost::graph::keywords::tag::weight_map,
  556. edge_weight_t,
  557. VertexListGraph
  558. >::type weight_map_type;
  559. typedef typename boost::property_traits<weight_map_type>::value_type D;
  560. const D inf = arg_pack[_distance_inf || detail::get_max<D>()];
  561. const D zero_actual = D();
  562. const D zero_d = arg_pack[_distance_zero | zero_actual];
  563. null_visitor null_vis;
  564. astar_visitor<null_visitor> default_visitor(null_vis);
  565. typename boost::parameter::binding<
  566. arg_pack_type,
  567. boost::graph::keywords::tag::visitor,
  568. dummy_property_map&
  569. >::type vis = arg_pack[_visitor | default_visitor];
  570. dummy_property_map dummy_prop;
  571. typename boost::parameter::binding<
  572. arg_pack_type,
  573. boost::graph::keywords::tag::predecessor_map,
  574. dummy_property_map&
  575. >::type pred_map = arg_pack[_predecessor_map | dummy_prop];
  576. boost::detail::make_property_map_from_arg_pack_gen<
  577. boost::graph::keywords::tag::rank_map,
  578. D
  579. > rank_map_gen(zero_actual);
  580. typename boost::detail::map_maker<
  581. VertexListGraph,
  582. arg_pack_type,
  583. boost::graph::keywords::tag::rank_map,
  584. D
  585. >::map_type r_map = rank_map_gen(g, arg_pack);
  586. boost::detail::make_property_map_from_arg_pack_gen<
  587. boost::graph::keywords::tag::distance_map,
  588. D
  589. > dist_map_gen(zero_actual);
  590. typename boost::detail::map_maker<
  591. VertexListGraph,
  592. arg_pack_type,
  593. boost::graph::keywords::tag::distance_map,
  594. D
  595. >::map_type dist_map = dist_map_gen(g, arg_pack);
  596. weight_map_type w_map = detail::override_const_property(arg_pack, _weight_map, g, edge_weight);
  597. typename boost::detail::map_maker<
  598. VertexListGraph,
  599. arg_pack_type,
  600. boost::graph::keywords::tag::color_map,
  601. boost::default_color_type
  602. >::map_type c_map = boost::detail::make_color_map_from_arg_pack(g, arg_pack);
  603. typename boost::detail::override_const_property_result<
  604. arg_pack_type,
  605. boost::graph::keywords::tag::vertex_index_map,
  606. vertex_index_t,
  607. VertexListGraph
  608. >::type v_i_map = detail::override_const_property(arg_pack, _vertex_index_map, g, vertex_index);
  609. std::less<D> default_compare;
  610. typename boost::parameter::binding<
  611. arg_pack_type,
  612. boost::graph::keywords::tag::distance_compare,
  613. std::less<D>&
  614. >::type dist_comp = arg_pack[_distance_compare | default_compare];
  615. closed_plus<D> default_combine(inf);
  616. typename boost::parameter::binding<
  617. arg_pack_type,
  618. boost::graph::keywords::tag::distance_combine,
  619. closed_plus<D>&
  620. >::type dist_comb = arg_pack[_distance_combine | default_combine];
  621. astar_search_no_init
  622. (g, s, h,
  623. vis,
  624. pred_map,
  625. r_map,
  626. dist_map,
  627. w_map,
  628. c_map,
  629. v_i_map,
  630. dist_comp,
  631. dist_comb,
  632. inf,
  633. zero_d);
  634. }
  635. template <typename VertexListGraph,
  636. typename AStarHeuristic,
  637. typename P, typename T, typename R>
  638. void
  639. astar_search_no_init_tree
  640. (const VertexListGraph &g,
  641. typename graph_traits<VertexListGraph>::vertex_descriptor s,
  642. AStarHeuristic h, const bgl_named_params<P, T, R>& params)
  643. {
  644. using namespace boost::graph::keywords;
  645. typedef bgl_named_params<P, T, R> params_type;
  646. BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(params_type, params)
  647. typedef typename boost::detail::override_const_property_result<
  648. arg_pack_type,
  649. boost::graph::keywords::tag::weight_map,
  650. edge_weight_t,
  651. VertexListGraph
  652. >::type weight_map_type;
  653. typedef typename boost::property_traits<weight_map_type>::value_type D;
  654. const D inf = arg_pack[_distance_inf || detail::get_max<D>()];
  655. const D zero_actual = D();
  656. const D zero_d = arg_pack[_distance_zero | zero_actual];
  657. null_visitor null_vis;
  658. astar_visitor<null_visitor> default_visitor(null_vis);
  659. typename boost::parameter::binding<
  660. arg_pack_type,
  661. boost::graph::keywords::tag::visitor,
  662. dummy_property_map&
  663. >::type vis = arg_pack[_visitor | default_visitor];
  664. dummy_property_map dummy_prop;
  665. typename boost::parameter::binding<
  666. arg_pack_type,
  667. boost::graph::keywords::tag::predecessor_map,
  668. dummy_property_map&
  669. >::type pred_map = arg_pack[_predecessor_map | dummy_prop];
  670. boost::detail::make_property_map_from_arg_pack_gen<
  671. boost::graph::keywords::tag::rank_map,
  672. D
  673. > rank_map_gen(zero_actual);
  674. typename boost::detail::map_maker<
  675. VertexListGraph,
  676. arg_pack_type,
  677. boost::graph::keywords::tag::rank_map,
  678. D
  679. >::map_type r_map = rank_map_gen(g, arg_pack);
  680. boost::detail::make_property_map_from_arg_pack_gen<
  681. boost::graph::keywords::tag::distance_map,
  682. D
  683. > dist_map_gen(zero_actual);
  684. typename boost::detail::map_maker<
  685. VertexListGraph,
  686. arg_pack_type,
  687. boost::graph::keywords::tag::distance_map,
  688. D
  689. >::map_type dist_map = dist_map_gen(g, arg_pack);
  690. weight_map_type w_map = detail::override_const_property(arg_pack, _weight_map, g, edge_weight);
  691. std::less<D> default_compare;
  692. typename boost::parameter::binding<
  693. arg_pack_type,
  694. boost::graph::keywords::tag::distance_compare,
  695. std::less<D>&
  696. >::type dist_comp = arg_pack[_distance_compare | default_compare];
  697. closed_plus<D> default_combine(inf);
  698. typename boost::parameter::binding<
  699. arg_pack_type,
  700. boost::graph::keywords::tag::distance_combine,
  701. closed_plus<D>&
  702. >::type dist_comb = arg_pack[_distance_combine | default_combine];
  703. astar_search_no_init_tree
  704. (g, s, h,
  705. vis,
  706. pred_map,
  707. r_map,
  708. dist_map,
  709. w_map,
  710. dist_comp,
  711. dist_comb,
  712. inf,
  713. zero_d);
  714. }
  715. } // namespace boost
  716. #endif // BOOST_GRAPH_ASTAR_SEARCH_HPP