astar_search.hpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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. {
  29. template < class Heuristic, class Graph > struct AStarHeuristicConcept
  30. {
  31. void constraints()
  32. {
  33. BOOST_CONCEPT_ASSERT((CopyConstructibleConcept< Heuristic >));
  34. h(u);
  35. }
  36. Heuristic h;
  37. typename graph_traits< Graph >::vertex_descriptor u;
  38. };
  39. template < class Graph, class CostType > 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 > struct AStarVisitorConcept
  49. {
  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. {
  70. public:
  71. astar_visitor() {}
  72. astar_visitor(Visitors vis) : bfs_visitor< Visitors >(vis) {}
  73. template < class Edge, class Graph >
  74. void edge_relaxed(Edge e, const Graph& g)
  75. {
  76. invoke_visitors(this->m_vis, e, g, on_edge_relaxed());
  77. }
  78. template < class Edge, class Graph >
  79. void edge_not_relaxed(Edge e, const Graph& g)
  80. {
  81. invoke_visitors(this->m_vis, e, g, on_edge_not_relaxed());
  82. }
  83. private:
  84. template < class Edge, class Graph > void tree_edge(Edge e, const Graph& g)
  85. {
  86. }
  87. template < class Edge, class Graph >
  88. void non_tree_edge(Edge e, const Graph& g)
  89. {
  90. }
  91. };
  92. template < class Visitors >
  93. astar_visitor< Visitors > make_astar_visitor(Visitors vis)
  94. {
  95. return astar_visitor< Visitors >(vis);
  96. }
  97. typedef astar_visitor<> default_astar_visitor;
  98. namespace detail
  99. {
  100. template < class AStarHeuristic, class UniformCostVisitor,
  101. class UpdatableQueue, class PredecessorMap, class CostMap,
  102. class DistanceMap, class WeightMap, class ColorMap,
  103. class BinaryFunction, class BinaryPredicate >
  104. struct astar_bfs_visitor
  105. {
  106. typedef typename property_traits< CostMap >::value_type C;
  107. typedef typename property_traits< ColorMap >::value_type ColorValue;
  108. typedef color_traits< ColorValue > Color;
  109. typedef
  110. typename property_traits< DistanceMap >::value_type distance_type;
  111. astar_bfs_visitor(AStarHeuristic h, UniformCostVisitor vis,
  112. UpdatableQueue& Q, PredecessorMap p, CostMap c, DistanceMap d,
  113. WeightMap w, ColorMap col, BinaryFunction combine,
  114. BinaryPredicate compare, C zero)
  115. : m_h(h)
  116. , m_vis(vis)
  117. , m_Q(Q)
  118. , m_predecessor(p)
  119. , m_cost(c)
  120. , m_distance(d)
  121. , m_weight(w)
  122. , m_color(col)
  123. , m_combine(combine)
  124. , m_compare(compare)
  125. , m_zero(zero)
  126. {
  127. }
  128. template < class Vertex, class Graph >
  129. void initialize_vertex(Vertex u, const Graph& g)
  130. {
  131. m_vis.initialize_vertex(u, g);
  132. }
  133. template < class Vertex, class Graph >
  134. void discover_vertex(Vertex u, const Graph& g)
  135. {
  136. m_vis.discover_vertex(u, g);
  137. }
  138. template < class Vertex, class Graph >
  139. void examine_vertex(Vertex u, const Graph& g)
  140. {
  141. m_vis.examine_vertex(u, g);
  142. }
  143. template < class Vertex, class Graph >
  144. void finish_vertex(Vertex u, const Graph& g)
  145. {
  146. m_vis.finish_vertex(u, g);
  147. }
  148. template < class Edge, class Graph >
  149. void examine_edge(Edge e, const Graph& g)
  150. {
  151. if (m_compare(get(m_weight, e), m_zero))
  152. BOOST_THROW_EXCEPTION(negative_edge());
  153. m_vis.examine_edge(e, g);
  154. }
  155. template < class Edge, class Graph >
  156. void non_tree_edge(Edge, const Graph&)
  157. {
  158. }
  159. template < class Edge, class Graph >
  160. void tree_edge(Edge e, const Graph& g)
  161. {
  162. using boost::get;
  163. bool m_decreased = relax(e, g, m_weight, m_predecessor, m_distance,
  164. m_combine, m_compare);
  165. if (m_decreased)
  166. {
  167. m_vis.edge_relaxed(e, g);
  168. put(m_cost, target(e, g),
  169. m_combine(
  170. get(m_distance, target(e, g)), m_h(target(e, g))));
  171. }
  172. else
  173. m_vis.edge_not_relaxed(e, g);
  174. }
  175. template < class Edge, class Graph >
  176. void gray_target(Edge e, const Graph& g)
  177. {
  178. using boost::get;
  179. bool m_decreased = relax(e, g, m_weight, m_predecessor, m_distance,
  180. m_combine, m_compare);
  181. if (m_decreased)
  182. {
  183. put(m_cost, target(e, g),
  184. m_combine(
  185. get(m_distance, target(e, g)), m_h(target(e, g))));
  186. m_Q.update(target(e, g));
  187. m_vis.edge_relaxed(e, g);
  188. }
  189. else
  190. m_vis.edge_not_relaxed(e, g);
  191. }
  192. template < class Edge, class Graph >
  193. void black_target(Edge e, const Graph& g)
  194. {
  195. using boost::get;
  196. bool m_decreased = relax(e, g, m_weight, m_predecessor, m_distance,
  197. m_combine, m_compare);
  198. if (m_decreased)
  199. {
  200. m_vis.edge_relaxed(e, g);
  201. put(m_cost, target(e, g),
  202. m_combine(
  203. get(m_distance, target(e, g)), m_h(target(e, g))));
  204. m_Q.push(target(e, g));
  205. put(m_color, target(e, g), Color::gray());
  206. m_vis.black_target(e, g);
  207. }
  208. else
  209. m_vis.edge_not_relaxed(e, g);
  210. }
  211. AStarHeuristic m_h;
  212. UniformCostVisitor m_vis;
  213. UpdatableQueue& m_Q;
  214. PredecessorMap m_predecessor;
  215. CostMap m_cost;
  216. DistanceMap m_distance;
  217. WeightMap m_weight;
  218. ColorMap m_color;
  219. BinaryFunction m_combine;
  220. BinaryPredicate m_compare;
  221. C m_zero;
  222. };
  223. } // namespace detail
  224. template < typename VertexListGraph, typename AStarHeuristic,
  225. typename AStarVisitor, typename PredecessorMap, typename CostMap,
  226. typename DistanceMap, typename WeightMap, typename ColorMap,
  227. typename VertexIndexMap, typename CompareFunction, typename CombineFunction,
  228. typename CostInf, typename CostZero >
  229. inline void astar_search_no_init(const VertexListGraph& g,
  230. typename graph_traits< VertexListGraph >::vertex_descriptor s,
  231. AStarHeuristic h, AStarVisitor vis, PredecessorMap predecessor,
  232. CostMap cost, DistanceMap distance, WeightMap weight, ColorMap color,
  233. VertexIndexMap index_map, CompareFunction compare, CombineFunction combine,
  234. CostInf /*inf*/, CostZero zero)
  235. {
  236. typedef typename graph_traits< VertexListGraph >::vertex_descriptor Vertex;
  237. typedef boost::vector_property_map< std::size_t, VertexIndexMap >
  238. IndexInHeapMap;
  239. IndexInHeapMap index_in_heap(index_map);
  240. typedef d_ary_heap_indirect< Vertex, 4, IndexInHeapMap, CostMap,
  241. CompareFunction >
  242. MutableQueue;
  243. MutableQueue Q(cost, index_in_heap, compare);
  244. detail::astar_bfs_visitor< AStarHeuristic, AStarVisitor, MutableQueue,
  245. PredecessorMap, CostMap, DistanceMap, WeightMap, ColorMap,
  246. CombineFunction, CompareFunction >
  247. bfs_vis(h, vis, Q, predecessor, cost, distance, weight, color, combine,
  248. compare, zero);
  249. breadth_first_visit(g, s, Q, bfs_vis, color);
  250. }
  251. namespace graph_detail
  252. {
  253. template < typename A, typename B > struct select1st
  254. {
  255. typedef std::pair< A, B > argument_type;
  256. typedef A result_type;
  257. A operator()(const std::pair< A, B >& p) const { return p.first; }
  258. };
  259. }
  260. template < typename VertexListGraph, typename AStarHeuristic,
  261. typename AStarVisitor, typename PredecessorMap, typename CostMap,
  262. typename DistanceMap, typename WeightMap, typename CompareFunction,
  263. typename CombineFunction, typename CostInf, typename CostZero >
  264. inline void astar_search_no_init_tree(const VertexListGraph& g,
  265. typename graph_traits< VertexListGraph >::vertex_descriptor s,
  266. AStarHeuristic h, AStarVisitor vis, PredecessorMap predecessor,
  267. CostMap cost, DistanceMap distance, WeightMap weight,
  268. CompareFunction compare, CombineFunction combine, CostInf /*inf*/,
  269. CostZero zero)
  270. {
  271. typedef typename graph_traits< VertexListGraph >::vertex_descriptor Vertex;
  272. typedef typename property_traits< DistanceMap >::value_type Distance;
  273. typedef d_ary_heap_indirect< std::pair< Distance, Vertex >, 4,
  274. null_property_map< std::pair< Distance, Vertex >, std::size_t >,
  275. function_property_map< graph_detail::select1st< Distance, Vertex >,
  276. std::pair< Distance, Vertex > >,
  277. CompareFunction >
  278. MutableQueue;
  279. MutableQueue Q(make_function_property_map< std::pair< Distance, Vertex > >(
  280. graph_detail::select1st< Distance, Vertex >()),
  281. null_property_map< std::pair< Distance, Vertex >, std::size_t >(),
  282. compare);
  283. vis.discover_vertex(s, g);
  284. Q.push(std::make_pair(get(cost, s), s));
  285. while (!Q.empty())
  286. {
  287. Vertex v;
  288. Distance v_rank;
  289. boost::tie(v_rank, v) = Q.top();
  290. Q.pop();
  291. vis.examine_vertex(v, g);
  292. BGL_FORALL_OUTEDGES_T(v, e, g, VertexListGraph)
  293. {
  294. Vertex w = target(e, g);
  295. vis.examine_edge(e, g);
  296. Distance e_weight = get(weight, e);
  297. if (compare(e_weight, zero))
  298. BOOST_THROW_EXCEPTION(negative_edge());
  299. bool decreased
  300. = relax(e, g, weight, predecessor, distance, combine, compare);
  301. combine(get(distance, v), e_weight);
  302. if (decreased)
  303. {
  304. vis.edge_relaxed(e, g);
  305. Distance w_rank = combine(get(distance, w), h(w));
  306. put(cost, w, w_rank);
  307. vis.discover_vertex(w, g);
  308. Q.push(std::make_pair(w_rank, w));
  309. }
  310. else
  311. {
  312. vis.edge_not_relaxed(e, g);
  313. }
  314. }
  315. vis.finish_vertex(v, g);
  316. }
  317. }
  318. // Non-named parameter interface
  319. template < typename VertexListGraph, typename AStarHeuristic,
  320. typename AStarVisitor, typename PredecessorMap, typename CostMap,
  321. typename DistanceMap, typename WeightMap, typename VertexIndexMap,
  322. typename ColorMap, typename CompareFunction, typename CombineFunction,
  323. typename CostInf, typename CostZero >
  324. inline void astar_search(const VertexListGraph& g,
  325. typename graph_traits< VertexListGraph >::vertex_descriptor s,
  326. AStarHeuristic h, AStarVisitor vis, PredecessorMap predecessor,
  327. CostMap cost, DistanceMap distance, WeightMap weight,
  328. VertexIndexMap index_map, ColorMap color, CompareFunction compare,
  329. CombineFunction combine, CostInf inf, CostZero zero)
  330. {
  331. typedef typename property_traits< ColorMap >::value_type ColorValue;
  332. typedef color_traits< ColorValue > Color;
  333. typename graph_traits< VertexListGraph >::vertex_iterator ui, ui_end;
  334. for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui)
  335. {
  336. put(color, *ui, Color::white());
  337. put(distance, *ui, inf);
  338. put(cost, *ui, inf);
  339. put(predecessor, *ui, *ui);
  340. vis.initialize_vertex(*ui, g);
  341. }
  342. put(distance, s, zero);
  343. put(cost, s, h(s));
  344. astar_search_no_init(g, s, h, vis, predecessor, cost, distance, weight,
  345. color, index_map, compare, combine, inf, zero);
  346. }
  347. // Non-named parameter interface
  348. template < typename VertexListGraph, typename AStarHeuristic,
  349. typename AStarVisitor, typename PredecessorMap, typename CostMap,
  350. typename DistanceMap, typename WeightMap, typename CompareFunction,
  351. typename CombineFunction, typename CostInf, typename CostZero >
  352. inline void astar_search_tree(const VertexListGraph& g,
  353. typename graph_traits< VertexListGraph >::vertex_descriptor s,
  354. AStarHeuristic h, AStarVisitor vis, PredecessorMap predecessor,
  355. CostMap cost, DistanceMap distance, WeightMap weight,
  356. CompareFunction compare, CombineFunction combine, CostInf inf,
  357. CostZero zero)
  358. {
  359. typename graph_traits< VertexListGraph >::vertex_iterator ui, ui_end;
  360. for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui)
  361. {
  362. put(distance, *ui, inf);
  363. put(cost, *ui, inf);
  364. put(predecessor, *ui, *ui);
  365. vis.initialize_vertex(*ui, g);
  366. }
  367. put(distance, s, zero);
  368. put(cost, s, h(s));
  369. astar_search_no_init_tree(g, s, h, vis, predecessor, cost, distance, weight,
  370. compare, combine, inf, zero);
  371. }
  372. // Named parameter interfaces
  373. template < typename VertexListGraph, typename AStarHeuristic, typename P,
  374. typename T, typename R >
  375. void astar_search(const VertexListGraph& g,
  376. typename graph_traits< VertexListGraph >::vertex_descriptor s,
  377. AStarHeuristic h, const bgl_named_params< P, T, R >& params)
  378. {
  379. using namespace boost::graph::keywords;
  380. typedef bgl_named_params< P, T, R > params_type;
  381. BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(params_type, params)
  382. // Distance type is the value type of the distance map if there is one,
  383. // otherwise the value type of the weight map.
  384. typedef
  385. typename boost::detail::override_const_property_result< arg_pack_type,
  386. boost::graph::keywords::tag::weight_map, edge_weight_t,
  387. VertexListGraph >::type weight_map_type;
  388. typedef typename boost::property_traits< weight_map_type >::value_type D;
  389. const D inf = arg_pack[_distance_inf || detail::get_max< D >()];
  390. const D zero_actual = D();
  391. const D zero_d = arg_pack[_distance_zero | zero_actual];
  392. null_visitor null_vis;
  393. astar_visitor< null_visitor > default_visitor(null_vis);
  394. typename boost::parameter::binding< arg_pack_type,
  395. boost::graph::keywords::tag::visitor, dummy_property_map& >::type vis
  396. = arg_pack[_visitor | default_visitor];
  397. dummy_property_map dummy_prop;
  398. typename boost::parameter::binding< arg_pack_type,
  399. boost::graph::keywords::tag::predecessor_map,
  400. dummy_property_map& >::type pred_map
  401. = arg_pack[_predecessor_map | dummy_prop];
  402. boost::detail::make_property_map_from_arg_pack_gen<
  403. boost::graph::keywords::tag::rank_map, D >
  404. rank_map_gen(zero_actual);
  405. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  406. boost::graph::keywords::tag::rank_map, D >::map_type r_map
  407. = rank_map_gen(g, arg_pack);
  408. boost::detail::make_property_map_from_arg_pack_gen<
  409. boost::graph::keywords::tag::distance_map, D >
  410. dist_map_gen(zero_actual);
  411. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  412. boost::graph::keywords::tag::distance_map, D >::map_type dist_map
  413. = dist_map_gen(g, arg_pack);
  414. weight_map_type w_map = detail::override_const_property(
  415. arg_pack, _weight_map, g, edge_weight);
  416. typename boost::detail::override_const_property_result< arg_pack_type,
  417. boost::graph::keywords::tag::vertex_index_map, vertex_index_t,
  418. VertexListGraph >::type v_i_map
  419. = detail::override_const_property(
  420. arg_pack, _vertex_index_map, g, vertex_index);
  421. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  422. boost::graph::keywords::tag::color_map,
  423. boost::default_color_type >::map_type c_map
  424. = boost::detail::make_color_map_from_arg_pack(g, arg_pack);
  425. std::less< D > default_compare;
  426. typename boost::parameter::binding< arg_pack_type,
  427. boost::graph::keywords::tag::distance_compare, std::less< D >& >::type
  428. dist_comp
  429. = arg_pack[_distance_compare | default_compare];
  430. closed_plus< D > default_combine(inf);
  431. typename boost::parameter::binding< arg_pack_type,
  432. boost::graph::keywords::tag::distance_combine, closed_plus< D >& >::type
  433. dist_comb
  434. = arg_pack[_distance_combine | default_combine];
  435. astar_search(g, s, h, vis, pred_map, r_map, dist_map, w_map, v_i_map, c_map,
  436. dist_comp, dist_comb, inf, zero_d);
  437. }
  438. template < typename VertexListGraph, typename AStarHeuristic, typename P,
  439. typename T, typename R >
  440. void astar_search_tree(const VertexListGraph& g,
  441. typename graph_traits< VertexListGraph >::vertex_descriptor s,
  442. AStarHeuristic h, const bgl_named_params< P, T, R >& params)
  443. {
  444. using namespace boost::graph::keywords;
  445. typedef bgl_named_params< P, T, R > params_type;
  446. BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(params_type, params)
  447. // Distance type is the value type of the distance map if there is one,
  448. // otherwise the value type of the weight map.
  449. typedef
  450. typename boost::detail::override_const_property_result< arg_pack_type,
  451. boost::graph::keywords::tag::weight_map, edge_weight_t,
  452. VertexListGraph >::type weight_map_type;
  453. typedef typename boost::property_traits< weight_map_type >::value_type D;
  454. const D inf = arg_pack[_distance_inf || detail::get_max< D >()];
  455. const D zero_actual = D();
  456. const D zero_d = arg_pack[_distance_zero | zero_actual];
  457. null_visitor null_vis;
  458. astar_visitor< null_visitor > default_visitor(null_vis);
  459. typename boost::parameter::binding< arg_pack_type,
  460. boost::graph::keywords::tag::visitor, dummy_property_map& >::type vis
  461. = arg_pack[_visitor | default_visitor];
  462. dummy_property_map dummy_prop;
  463. typename boost::parameter::binding< arg_pack_type,
  464. boost::graph::keywords::tag::predecessor_map,
  465. dummy_property_map& >::type pred_map
  466. = arg_pack[_predecessor_map | dummy_prop];
  467. boost::detail::make_property_map_from_arg_pack_gen<
  468. boost::graph::keywords::tag::rank_map, D >
  469. rank_map_gen(zero_actual);
  470. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  471. boost::graph::keywords::tag::rank_map, D >::map_type r_map
  472. = rank_map_gen(g, arg_pack);
  473. boost::detail::make_property_map_from_arg_pack_gen<
  474. boost::graph::keywords::tag::distance_map, D >
  475. dist_map_gen(zero_actual);
  476. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  477. boost::graph::keywords::tag::distance_map, D >::map_type dist_map
  478. = dist_map_gen(g, arg_pack);
  479. weight_map_type w_map = detail::override_const_property(
  480. arg_pack, _weight_map, g, edge_weight);
  481. std::less< D > default_compare;
  482. typename boost::parameter::binding< arg_pack_type,
  483. boost::graph::keywords::tag::distance_compare, std::less< D >& >::type
  484. dist_comp
  485. = arg_pack[_distance_compare | default_compare];
  486. closed_plus< D > default_combine(inf);
  487. typename boost::parameter::binding< arg_pack_type,
  488. boost::graph::keywords::tag::distance_combine, closed_plus< D >& >::type
  489. dist_comb
  490. = arg_pack[_distance_combine | default_combine];
  491. astar_search_tree(g, s, h, vis, pred_map, r_map, dist_map, w_map, dist_comp,
  492. dist_comb, inf, zero_d);
  493. }
  494. template < typename VertexListGraph, typename AStarHeuristic, typename P,
  495. typename T, typename R >
  496. void astar_search_no_init(const VertexListGraph& g,
  497. typename graph_traits< VertexListGraph >::vertex_descriptor s,
  498. AStarHeuristic h, const bgl_named_params< P, T, R >& params)
  499. {
  500. using namespace boost::graph::keywords;
  501. typedef bgl_named_params< P, T, R > params_type;
  502. BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(params_type, params)
  503. typedef
  504. typename boost::detail::override_const_property_result< arg_pack_type,
  505. boost::graph::keywords::tag::weight_map, edge_weight_t,
  506. VertexListGraph >::type weight_map_type;
  507. typedef typename boost::property_traits< weight_map_type >::value_type D;
  508. const D inf = arg_pack[_distance_inf || detail::get_max< D >()];
  509. const D zero_actual = D();
  510. const D zero_d = arg_pack[_distance_zero | zero_actual];
  511. null_visitor null_vis;
  512. astar_visitor< null_visitor > default_visitor(null_vis);
  513. typename boost::parameter::binding< arg_pack_type,
  514. boost::graph::keywords::tag::visitor, dummy_property_map& >::type vis
  515. = arg_pack[_visitor | default_visitor];
  516. dummy_property_map dummy_prop;
  517. typename boost::parameter::binding< arg_pack_type,
  518. boost::graph::keywords::tag::predecessor_map,
  519. dummy_property_map& >::type pred_map
  520. = arg_pack[_predecessor_map | dummy_prop];
  521. boost::detail::make_property_map_from_arg_pack_gen<
  522. boost::graph::keywords::tag::rank_map, D >
  523. rank_map_gen(zero_actual);
  524. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  525. boost::graph::keywords::tag::rank_map, D >::map_type r_map
  526. = rank_map_gen(g, arg_pack);
  527. boost::detail::make_property_map_from_arg_pack_gen<
  528. boost::graph::keywords::tag::distance_map, D >
  529. dist_map_gen(zero_actual);
  530. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  531. boost::graph::keywords::tag::distance_map, D >::map_type dist_map
  532. = dist_map_gen(g, arg_pack);
  533. weight_map_type w_map = detail::override_const_property(
  534. arg_pack, _weight_map, g, edge_weight);
  535. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  536. boost::graph::keywords::tag::color_map,
  537. boost::default_color_type >::map_type c_map
  538. = boost::detail::make_color_map_from_arg_pack(g, arg_pack);
  539. typename boost::detail::override_const_property_result< arg_pack_type,
  540. boost::graph::keywords::tag::vertex_index_map, vertex_index_t,
  541. VertexListGraph >::type v_i_map
  542. = detail::override_const_property(
  543. arg_pack, _vertex_index_map, g, vertex_index);
  544. std::less< D > default_compare;
  545. typename boost::parameter::binding< arg_pack_type,
  546. boost::graph::keywords::tag::distance_compare, std::less< D >& >::type
  547. dist_comp
  548. = arg_pack[_distance_compare | default_compare];
  549. closed_plus< D > default_combine(inf);
  550. typename boost::parameter::binding< arg_pack_type,
  551. boost::graph::keywords::tag::distance_combine, closed_plus< D >& >::type
  552. dist_comb
  553. = arg_pack[_distance_combine | default_combine];
  554. astar_search_no_init(g, s, h, vis, pred_map, r_map, dist_map, w_map, c_map,
  555. v_i_map, dist_comp, dist_comb, inf, zero_d);
  556. }
  557. template < typename VertexListGraph, typename AStarHeuristic, typename P,
  558. typename T, typename R >
  559. void astar_search_no_init_tree(const VertexListGraph& g,
  560. typename graph_traits< VertexListGraph >::vertex_descriptor s,
  561. AStarHeuristic h, const bgl_named_params< P, T, R >& params)
  562. {
  563. using namespace boost::graph::keywords;
  564. typedef bgl_named_params< P, T, R > params_type;
  565. BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(params_type, params)
  566. typedef
  567. typename boost::detail::override_const_property_result< arg_pack_type,
  568. boost::graph::keywords::tag::weight_map, edge_weight_t,
  569. VertexListGraph >::type weight_map_type;
  570. typedef typename boost::property_traits< weight_map_type >::value_type D;
  571. const D inf = arg_pack[_distance_inf || detail::get_max< D >()];
  572. const D zero_actual = D();
  573. const D zero_d = arg_pack[_distance_zero | zero_actual];
  574. null_visitor null_vis;
  575. astar_visitor< null_visitor > default_visitor(null_vis);
  576. typename boost::parameter::binding< arg_pack_type,
  577. boost::graph::keywords::tag::visitor, dummy_property_map& >::type vis
  578. = arg_pack[_visitor | default_visitor];
  579. dummy_property_map dummy_prop;
  580. typename boost::parameter::binding< arg_pack_type,
  581. boost::graph::keywords::tag::predecessor_map,
  582. dummy_property_map& >::type pred_map
  583. = arg_pack[_predecessor_map | dummy_prop];
  584. boost::detail::make_property_map_from_arg_pack_gen<
  585. boost::graph::keywords::tag::rank_map, D >
  586. rank_map_gen(zero_actual);
  587. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  588. boost::graph::keywords::tag::rank_map, D >::map_type r_map
  589. = rank_map_gen(g, arg_pack);
  590. boost::detail::make_property_map_from_arg_pack_gen<
  591. boost::graph::keywords::tag::distance_map, D >
  592. dist_map_gen(zero_actual);
  593. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  594. boost::graph::keywords::tag::distance_map, D >::map_type dist_map
  595. = dist_map_gen(g, arg_pack);
  596. weight_map_type w_map = detail::override_const_property(
  597. arg_pack, _weight_map, g, edge_weight);
  598. std::less< D > default_compare;
  599. typename boost::parameter::binding< arg_pack_type,
  600. boost::graph::keywords::tag::distance_compare, std::less< D >& >::type
  601. dist_comp
  602. = arg_pack[_distance_compare | default_compare];
  603. closed_plus< D > default_combine(inf);
  604. typename boost::parameter::binding< arg_pack_type,
  605. boost::graph::keywords::tag::distance_combine, closed_plus< D >& >::type
  606. dist_comb
  607. = arg_pack[_distance_combine | default_combine];
  608. astar_search_no_init_tree(g, s, h, vis, pred_map, r_map, dist_map, w_map,
  609. dist_comp, dist_comb, inf, zero_d);
  610. }
  611. } // namespace boost
  612. #endif // BOOST_GRAPH_ASTAR_SEARCH_HPP