astar_search.hpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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. if (decreased)
  302. {
  303. vis.edge_relaxed(e, g);
  304. Distance w_rank = combine(get(distance, w), h(w));
  305. put(cost, w, w_rank);
  306. vis.discover_vertex(w, g);
  307. Q.push(std::make_pair(w_rank, w));
  308. }
  309. else
  310. {
  311. vis.edge_not_relaxed(e, g);
  312. }
  313. }
  314. vis.finish_vertex(v, g);
  315. }
  316. }
  317. // Non-named parameter interface
  318. template < typename VertexListGraph, typename AStarHeuristic,
  319. typename AStarVisitor, typename PredecessorMap, typename CostMap,
  320. typename DistanceMap, typename WeightMap, typename VertexIndexMap,
  321. typename ColorMap, typename CompareFunction, typename CombineFunction,
  322. typename CostInf, typename CostZero >
  323. inline void astar_search(const VertexListGraph& g,
  324. typename graph_traits< VertexListGraph >::vertex_descriptor s,
  325. AStarHeuristic h, AStarVisitor vis, PredecessorMap predecessor,
  326. CostMap cost, DistanceMap distance, WeightMap weight,
  327. VertexIndexMap index_map, ColorMap color, CompareFunction compare,
  328. CombineFunction combine, CostInf inf, CostZero zero)
  329. {
  330. typedef typename property_traits< ColorMap >::value_type ColorValue;
  331. typedef color_traits< ColorValue > Color;
  332. typename graph_traits< VertexListGraph >::vertex_iterator ui, ui_end;
  333. for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui)
  334. {
  335. put(color, *ui, Color::white());
  336. put(distance, *ui, inf);
  337. put(cost, *ui, inf);
  338. put(predecessor, *ui, *ui);
  339. vis.initialize_vertex(*ui, g);
  340. }
  341. put(distance, s, zero);
  342. put(cost, s, h(s));
  343. astar_search_no_init(g, s, h, vis, predecessor, cost, distance, weight,
  344. color, index_map, compare, combine, inf, zero);
  345. }
  346. // Non-named parameter interface
  347. template < typename VertexListGraph, typename AStarHeuristic,
  348. typename AStarVisitor, typename PredecessorMap, typename CostMap,
  349. typename DistanceMap, typename WeightMap, typename CompareFunction,
  350. typename CombineFunction, typename CostInf, typename CostZero >
  351. inline void astar_search_tree(const VertexListGraph& g,
  352. typename graph_traits< VertexListGraph >::vertex_descriptor s,
  353. AStarHeuristic h, AStarVisitor vis, PredecessorMap predecessor,
  354. CostMap cost, DistanceMap distance, WeightMap weight,
  355. CompareFunction compare, CombineFunction combine, CostInf inf,
  356. CostZero zero)
  357. {
  358. typename graph_traits< VertexListGraph >::vertex_iterator ui, ui_end;
  359. for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui)
  360. {
  361. put(distance, *ui, inf);
  362. put(cost, *ui, inf);
  363. put(predecessor, *ui, *ui);
  364. vis.initialize_vertex(*ui, g);
  365. }
  366. put(distance, s, zero);
  367. put(cost, s, h(s));
  368. astar_search_no_init_tree(g, s, h, vis, predecessor, cost, distance, weight,
  369. compare, combine, inf, zero);
  370. }
  371. // Named parameter interfaces
  372. template < typename VertexListGraph, typename AStarHeuristic, typename P,
  373. typename T, typename R >
  374. void astar_search(const VertexListGraph& g,
  375. typename graph_traits< VertexListGraph >::vertex_descriptor s,
  376. AStarHeuristic h, const bgl_named_params< P, T, R >& params)
  377. {
  378. using namespace boost::graph::keywords;
  379. typedef bgl_named_params< P, T, R > params_type;
  380. BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(params_type, params)
  381. // Distance type is the value type of the distance map if there is one,
  382. // otherwise the value type of the weight map.
  383. typedef
  384. typename boost::detail::override_const_property_result< arg_pack_type,
  385. boost::graph::keywords::tag::weight_map, edge_weight_t,
  386. VertexListGraph >::type weight_map_type;
  387. typedef typename boost::property_traits< weight_map_type >::value_type D;
  388. const D inf = arg_pack[_distance_inf || detail::get_max< D >()];
  389. const D zero_actual = D();
  390. const D zero_d = arg_pack[_distance_zero | zero_actual];
  391. null_visitor null_vis;
  392. astar_visitor< null_visitor > default_visitor(null_vis);
  393. typename boost::parameter::binding< arg_pack_type,
  394. boost::graph::keywords::tag::visitor, dummy_property_map& >::type vis
  395. = arg_pack[_visitor | default_visitor];
  396. dummy_property_map dummy_prop;
  397. typename boost::parameter::binding< arg_pack_type,
  398. boost::graph::keywords::tag::predecessor_map,
  399. dummy_property_map& >::type pred_map
  400. = arg_pack[_predecessor_map | dummy_prop];
  401. boost::detail::make_property_map_from_arg_pack_gen<
  402. boost::graph::keywords::tag::rank_map, D >
  403. rank_map_gen(zero_actual);
  404. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  405. boost::graph::keywords::tag::rank_map, D >::map_type r_map
  406. = rank_map_gen(g, arg_pack);
  407. boost::detail::make_property_map_from_arg_pack_gen<
  408. boost::graph::keywords::tag::distance_map, D >
  409. dist_map_gen(zero_actual);
  410. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  411. boost::graph::keywords::tag::distance_map, D >::map_type dist_map
  412. = dist_map_gen(g, arg_pack);
  413. weight_map_type w_map = detail::override_const_property(
  414. arg_pack, _weight_map, g, edge_weight);
  415. typename boost::detail::override_const_property_result< arg_pack_type,
  416. boost::graph::keywords::tag::vertex_index_map, vertex_index_t,
  417. VertexListGraph >::type v_i_map
  418. = detail::override_const_property(
  419. arg_pack, _vertex_index_map, g, vertex_index);
  420. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  421. boost::graph::keywords::tag::color_map,
  422. boost::default_color_type >::map_type c_map
  423. = boost::detail::make_color_map_from_arg_pack(g, arg_pack);
  424. std::less< D > default_compare;
  425. typename boost::parameter::binding< arg_pack_type,
  426. boost::graph::keywords::tag::distance_compare, std::less< D >& >::type
  427. dist_comp
  428. = arg_pack[_distance_compare | default_compare];
  429. closed_plus< D > default_combine(inf);
  430. typename boost::parameter::binding< arg_pack_type,
  431. boost::graph::keywords::tag::distance_combine, closed_plus< D >& >::type
  432. dist_comb
  433. = arg_pack[_distance_combine | default_combine];
  434. astar_search(g, s, h, vis, pred_map, r_map, dist_map, w_map, v_i_map, c_map,
  435. dist_comp, dist_comb, inf, zero_d);
  436. }
  437. template < typename VertexListGraph, typename AStarHeuristic, typename P,
  438. typename T, typename R >
  439. void astar_search_tree(const VertexListGraph& g,
  440. typename graph_traits< VertexListGraph >::vertex_descriptor s,
  441. AStarHeuristic h, const bgl_named_params< P, T, R >& params)
  442. {
  443. using namespace boost::graph::keywords;
  444. typedef bgl_named_params< P, T, R > params_type;
  445. BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(params_type, params)
  446. // Distance type is the value type of the distance map if there is one,
  447. // otherwise the value type of the weight map.
  448. typedef
  449. typename boost::detail::override_const_property_result< arg_pack_type,
  450. boost::graph::keywords::tag::weight_map, edge_weight_t,
  451. VertexListGraph >::type weight_map_type;
  452. typedef typename boost::property_traits< weight_map_type >::value_type D;
  453. const D inf = arg_pack[_distance_inf || detail::get_max< D >()];
  454. const D zero_actual = D();
  455. const D zero_d = arg_pack[_distance_zero | zero_actual];
  456. null_visitor null_vis;
  457. astar_visitor< null_visitor > default_visitor(null_vis);
  458. typename boost::parameter::binding< arg_pack_type,
  459. boost::graph::keywords::tag::visitor, dummy_property_map& >::type vis
  460. = arg_pack[_visitor | default_visitor];
  461. dummy_property_map dummy_prop;
  462. typename boost::parameter::binding< arg_pack_type,
  463. boost::graph::keywords::tag::predecessor_map,
  464. dummy_property_map& >::type pred_map
  465. = arg_pack[_predecessor_map | dummy_prop];
  466. boost::detail::make_property_map_from_arg_pack_gen<
  467. boost::graph::keywords::tag::rank_map, D >
  468. rank_map_gen(zero_actual);
  469. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  470. boost::graph::keywords::tag::rank_map, D >::map_type r_map
  471. = rank_map_gen(g, arg_pack);
  472. boost::detail::make_property_map_from_arg_pack_gen<
  473. boost::graph::keywords::tag::distance_map, D >
  474. dist_map_gen(zero_actual);
  475. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  476. boost::graph::keywords::tag::distance_map, D >::map_type dist_map
  477. = dist_map_gen(g, arg_pack);
  478. weight_map_type w_map = detail::override_const_property(
  479. arg_pack, _weight_map, g, edge_weight);
  480. std::less< D > default_compare;
  481. typename boost::parameter::binding< arg_pack_type,
  482. boost::graph::keywords::tag::distance_compare, std::less< D >& >::type
  483. dist_comp
  484. = arg_pack[_distance_compare | default_compare];
  485. closed_plus< D > default_combine(inf);
  486. typename boost::parameter::binding< arg_pack_type,
  487. boost::graph::keywords::tag::distance_combine, closed_plus< D >& >::type
  488. dist_comb
  489. = arg_pack[_distance_combine | default_combine];
  490. astar_search_tree(g, s, h, vis, pred_map, r_map, dist_map, w_map, dist_comp,
  491. dist_comb, inf, zero_d);
  492. }
  493. template < typename VertexListGraph, typename AStarHeuristic, typename P,
  494. typename T, typename R >
  495. void astar_search_no_init(const VertexListGraph& g,
  496. typename graph_traits< VertexListGraph >::vertex_descriptor s,
  497. AStarHeuristic h, const bgl_named_params< P, T, R >& params)
  498. {
  499. using namespace boost::graph::keywords;
  500. typedef bgl_named_params< P, T, R > params_type;
  501. BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(params_type, params)
  502. typedef
  503. typename boost::detail::override_const_property_result< arg_pack_type,
  504. boost::graph::keywords::tag::weight_map, edge_weight_t,
  505. VertexListGraph >::type weight_map_type;
  506. typedef typename boost::property_traits< weight_map_type >::value_type D;
  507. const D inf = arg_pack[_distance_inf || detail::get_max< D >()];
  508. const D zero_actual = D();
  509. const D zero_d = arg_pack[_distance_zero | zero_actual];
  510. null_visitor null_vis;
  511. astar_visitor< null_visitor > default_visitor(null_vis);
  512. typename boost::parameter::binding< arg_pack_type,
  513. boost::graph::keywords::tag::visitor, dummy_property_map& >::type vis
  514. = arg_pack[_visitor | default_visitor];
  515. dummy_property_map dummy_prop;
  516. typename boost::parameter::binding< arg_pack_type,
  517. boost::graph::keywords::tag::predecessor_map,
  518. dummy_property_map& >::type pred_map
  519. = arg_pack[_predecessor_map | dummy_prop];
  520. boost::detail::make_property_map_from_arg_pack_gen<
  521. boost::graph::keywords::tag::rank_map, D >
  522. rank_map_gen(zero_actual);
  523. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  524. boost::graph::keywords::tag::rank_map, D >::map_type r_map
  525. = rank_map_gen(g, arg_pack);
  526. boost::detail::make_property_map_from_arg_pack_gen<
  527. boost::graph::keywords::tag::distance_map, D >
  528. dist_map_gen(zero_actual);
  529. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  530. boost::graph::keywords::tag::distance_map, D >::map_type dist_map
  531. = dist_map_gen(g, arg_pack);
  532. weight_map_type w_map = detail::override_const_property(
  533. arg_pack, _weight_map, g, edge_weight);
  534. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  535. boost::graph::keywords::tag::color_map,
  536. boost::default_color_type >::map_type c_map
  537. = boost::detail::make_color_map_from_arg_pack(g, arg_pack);
  538. typename boost::detail::override_const_property_result< arg_pack_type,
  539. boost::graph::keywords::tag::vertex_index_map, vertex_index_t,
  540. VertexListGraph >::type v_i_map
  541. = detail::override_const_property(
  542. arg_pack, _vertex_index_map, g, vertex_index);
  543. std::less< D > default_compare;
  544. typename boost::parameter::binding< arg_pack_type,
  545. boost::graph::keywords::tag::distance_compare, std::less< D >& >::type
  546. dist_comp
  547. = arg_pack[_distance_compare | default_compare];
  548. closed_plus< D > default_combine(inf);
  549. typename boost::parameter::binding< arg_pack_type,
  550. boost::graph::keywords::tag::distance_combine, closed_plus< D >& >::type
  551. dist_comb
  552. = arg_pack[_distance_combine | default_combine];
  553. astar_search_no_init(g, s, h, vis, pred_map, r_map, dist_map, w_map, c_map,
  554. v_i_map, dist_comp, dist_comb, inf, zero_d);
  555. }
  556. template < typename VertexListGraph, typename AStarHeuristic, typename P,
  557. typename T, typename R >
  558. void astar_search_no_init_tree(const VertexListGraph& g,
  559. typename graph_traits< VertexListGraph >::vertex_descriptor s,
  560. AStarHeuristic h, const bgl_named_params< P, T, R >& params)
  561. {
  562. using namespace boost::graph::keywords;
  563. typedef bgl_named_params< P, T, R > params_type;
  564. BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(params_type, params)
  565. typedef
  566. typename boost::detail::override_const_property_result< arg_pack_type,
  567. boost::graph::keywords::tag::weight_map, edge_weight_t,
  568. VertexListGraph >::type weight_map_type;
  569. typedef typename boost::property_traits< weight_map_type >::value_type D;
  570. const D inf = arg_pack[_distance_inf || detail::get_max< D >()];
  571. const D zero_actual = D();
  572. const D zero_d = arg_pack[_distance_zero | zero_actual];
  573. null_visitor null_vis;
  574. astar_visitor< null_visitor > default_visitor(null_vis);
  575. typename boost::parameter::binding< arg_pack_type,
  576. boost::graph::keywords::tag::visitor, dummy_property_map& >::type vis
  577. = arg_pack[_visitor | default_visitor];
  578. dummy_property_map dummy_prop;
  579. typename boost::parameter::binding< arg_pack_type,
  580. boost::graph::keywords::tag::predecessor_map,
  581. dummy_property_map& >::type pred_map
  582. = arg_pack[_predecessor_map | dummy_prop];
  583. boost::detail::make_property_map_from_arg_pack_gen<
  584. boost::graph::keywords::tag::rank_map, D >
  585. rank_map_gen(zero_actual);
  586. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  587. boost::graph::keywords::tag::rank_map, D >::map_type r_map
  588. = rank_map_gen(g, arg_pack);
  589. boost::detail::make_property_map_from_arg_pack_gen<
  590. boost::graph::keywords::tag::distance_map, D >
  591. dist_map_gen(zero_actual);
  592. typename boost::detail::map_maker< VertexListGraph, arg_pack_type,
  593. boost::graph::keywords::tag::distance_map, D >::map_type dist_map
  594. = dist_map_gen(g, arg_pack);
  595. weight_map_type w_map = detail::override_const_property(
  596. arg_pack, _weight_map, g, edge_weight);
  597. std::less< D > default_compare;
  598. typename boost::parameter::binding< arg_pack_type,
  599. boost::graph::keywords::tag::distance_compare, std::less< D >& >::type
  600. dist_comp
  601. = arg_pack[_distance_compare | default_compare];
  602. closed_plus< D > default_combine(inf);
  603. typename boost::parameter::binding< arg_pack_type,
  604. boost::graph::keywords::tag::distance_combine, closed_plus< D >& >::type
  605. dist_comb
  606. = arg_pack[_distance_combine | default_combine];
  607. astar_search_no_init_tree(g, s, h, vis, pred_map, r_map, dist_map, w_map,
  608. dist_comp, dist_comb, inf, zero_d);
  609. }
  610. } // namespace boost
  611. #endif // BOOST_GRAPH_ASTAR_SEARCH_HPP