dijkstra_shortest_paths.hpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. //=======================================================================
  2. // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
  3. // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
  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. //
  11. // Revision History:
  12. // 04 April 2001: Added named parameter variant. (Jeremy Siek)
  13. // 01 April 2001: Modified to use new <boost/limits.hpp> header. (JMaddock)
  14. //
  15. #ifndef BOOST_GRAPH_DIJKSTRA_HPP
  16. #define BOOST_GRAPH_DIJKSTRA_HPP
  17. #include <functional>
  18. #include <boost/limits.hpp>
  19. #include <boost/graph/named_function_params.hpp>
  20. #include <boost/graph/breadth_first_search.hpp>
  21. #include <boost/graph/relax.hpp>
  22. #include <boost/pending/indirect_cmp.hpp>
  23. #include <boost/graph/exception.hpp>
  24. #include <boost/graph/overloading.hpp>
  25. #include <boost/smart_ptr.hpp>
  26. #include <boost/graph/detail/d_ary_heap.hpp>
  27. #include <boost/graph/two_bit_color_map.hpp>
  28. #include <boost/graph/detail/mpi_include.hpp>
  29. #include <boost/property_map/property_map.hpp>
  30. #include <boost/property_map/vector_property_map.hpp>
  31. #include <boost/type_traits.hpp>
  32. #include <boost/concept/assert.hpp>
  33. #ifdef BOOST_GRAPH_DIJKSTRA_TESTING
  34. # include <boost/pending/mutable_queue.hpp>
  35. #endif // BOOST_GRAPH_DIJKSTRA_TESTING
  36. namespace boost {
  37. /**
  38. * @brief Updates a particular value in a queue used by Dijkstra's
  39. * algorithm.
  40. *
  41. * This routine is called by Dijkstra's algorithm after it has
  42. * decreased the distance from the source vertex to the given @p
  43. * vertex. By default, this routine will just call @c
  44. * Q.update(vertex). However, other queues may provide more
  45. * specialized versions of this routine.
  46. *
  47. * @param Q the queue that will be updated.
  48. * @param vertex the vertex whose distance has been updated
  49. * @param old_distance the previous distance to @p vertex
  50. */
  51. template<typename Buffer, typename Vertex, typename DistanceType>
  52. inline void
  53. dijkstra_queue_update(Buffer& Q, Vertex vertex, DistanceType old_distance)
  54. {
  55. (void)old_distance;
  56. Q.update(vertex);
  57. }
  58. template <class Visitor, class Graph>
  59. struct DijkstraVisitorConcept {
  60. void constraints() {
  61. BOOST_CONCEPT_ASSERT(( CopyConstructibleConcept<Visitor> ));
  62. vis.initialize_vertex(u, g);
  63. vis.discover_vertex(u, g);
  64. vis.examine_vertex(u, g);
  65. vis.examine_edge(e, g);
  66. vis.edge_relaxed(e, g);
  67. vis.edge_not_relaxed(e, g);
  68. vis.finish_vertex(u, g);
  69. }
  70. Visitor vis;
  71. Graph g;
  72. typename graph_traits<Graph>::vertex_descriptor u;
  73. typename graph_traits<Graph>::edge_descriptor e;
  74. };
  75. template <class Visitors = null_visitor>
  76. class dijkstra_visitor : public bfs_visitor<Visitors> {
  77. public:
  78. dijkstra_visitor() { }
  79. dijkstra_visitor(Visitors vis)
  80. : bfs_visitor<Visitors>(vis) { }
  81. template <class Edge, class Graph>
  82. void edge_relaxed(Edge e, Graph& g) {
  83. invoke_visitors(this->m_vis, e, g, on_edge_relaxed());
  84. }
  85. template <class Edge, class Graph>
  86. void edge_not_relaxed(Edge e, Graph& g) {
  87. invoke_visitors(this->m_vis, e, g, on_edge_not_relaxed());
  88. }
  89. private:
  90. template <class Edge, class Graph>
  91. void tree_edge(Edge u, Graph& g) { }
  92. };
  93. template <class Visitors>
  94. dijkstra_visitor<Visitors>
  95. make_dijkstra_visitor(Visitors vis) {
  96. return dijkstra_visitor<Visitors>(vis);
  97. }
  98. typedef dijkstra_visitor<> default_dijkstra_visitor;
  99. namespace detail {
  100. template <class UniformCostVisitor, class UpdatableQueue,
  101. class WeightMap, class PredecessorMap, class DistanceMap,
  102. class BinaryFunction, class BinaryPredicate>
  103. struct dijkstra_bfs_visitor
  104. {
  105. typedef typename property_traits<DistanceMap>::value_type D;
  106. typedef typename property_traits<WeightMap>::value_type W;
  107. dijkstra_bfs_visitor(UniformCostVisitor vis, UpdatableQueue& Q,
  108. WeightMap w, PredecessorMap p, DistanceMap d,
  109. BinaryFunction combine, BinaryPredicate compare,
  110. D zero)
  111. : m_vis(vis), m_Q(Q), m_weight(w), m_predecessor(p), m_distance(d),
  112. m_combine(combine), m_compare(compare), m_zero(zero) { }
  113. template <class Edge, class Graph>
  114. void tree_edge(Edge e, Graph& g) {
  115. bool decreased = relax_target(e, g, m_weight, m_predecessor, m_distance,
  116. m_combine, m_compare);
  117. if (decreased)
  118. m_vis.edge_relaxed(e, g);
  119. else
  120. m_vis.edge_not_relaxed(e, g);
  121. }
  122. template <class Edge, class Graph>
  123. void gray_target(Edge e, Graph& g) {
  124. D old_distance = get(m_distance, target(e, g));
  125. bool decreased = relax_target(e, g, m_weight, m_predecessor, m_distance,
  126. m_combine, m_compare);
  127. if (decreased) {
  128. dijkstra_queue_update(m_Q, target(e, g), old_distance);
  129. m_vis.edge_relaxed(e, g);
  130. } else
  131. m_vis.edge_not_relaxed(e, g);
  132. }
  133. template <class Vertex, class Graph>
  134. void initialize_vertex(Vertex u, Graph& g)
  135. { m_vis.initialize_vertex(u, g); }
  136. template <class Edge, class Graph>
  137. void non_tree_edge(Edge, Graph&) { }
  138. template <class Vertex, class Graph>
  139. void discover_vertex(Vertex u, Graph& g) { m_vis.discover_vertex(u, g); }
  140. template <class Vertex, class Graph>
  141. void examine_vertex(Vertex u, Graph& g) { m_vis.examine_vertex(u, g); }
  142. template <class Edge, class Graph>
  143. void examine_edge(Edge e, Graph& g) {
  144. // Test for negative-weight edges:
  145. //
  146. // Reasons that other comparisons do not work:
  147. //
  148. // m_compare(e_weight, D(0)):
  149. // m_compare only needs to work on distances, not weights, and those
  150. // types do not need to be the same (bug 8398,
  151. // https://svn.boost.org/trac/boost/ticket/8398).
  152. // m_compare(m_combine(source_dist, e_weight), source_dist):
  153. // if m_combine is project2nd (as in prim_minimum_spanning_tree),
  154. // this test will claim that the edge weight is negative whenever
  155. // the edge weight is less than source_dist, even if both of those
  156. // are positive (bug 9012,
  157. // https://svn.boost.org/trac/boost/ticket/9012).
  158. // m_compare(m_combine(e_weight, source_dist), source_dist):
  159. // would fix project2nd issue, but documentation only requires that
  160. // m_combine be able to take a distance and a weight (in that order)
  161. // and return a distance.
  162. // W e_weight = get(m_weight, e);
  163. // sd_plus_ew = source_dist + e_weight.
  164. // D sd_plus_ew = m_combine(source_dist, e_weight);
  165. // sd_plus_2ew = source_dist + 2 * e_weight.
  166. // D sd_plus_2ew = m_combine(sd_plus_ew, e_weight);
  167. // The test here is equivalent to e_weight < 0 if m_combine has a
  168. // cancellation law, but always returns false when m_combine is a
  169. // projection operator.
  170. if (m_compare(m_combine(m_zero, get(m_weight, e)), m_zero))
  171. boost::throw_exception(negative_edge());
  172. // End of test for negative-weight edges.
  173. m_vis.examine_edge(e, g);
  174. }
  175. template <class Edge, class Graph>
  176. void black_target(Edge, Graph&) { }
  177. template <class Vertex, class Graph>
  178. void finish_vertex(Vertex u, Graph& g) { m_vis.finish_vertex(u, g); }
  179. UniformCostVisitor m_vis;
  180. UpdatableQueue& m_Q;
  181. WeightMap m_weight;
  182. PredecessorMap m_predecessor;
  183. DistanceMap m_distance;
  184. BinaryFunction m_combine;
  185. BinaryPredicate m_compare;
  186. D m_zero;
  187. };
  188. } // namespace detail
  189. namespace detail {
  190. template <class Graph, class IndexMap, class Value, bool KnownNumVertices>
  191. struct vertex_property_map_generator_helper {};
  192. template <class Graph, class IndexMap, class Value>
  193. struct vertex_property_map_generator_helper<Graph, IndexMap, Value, true> {
  194. typedef boost::iterator_property_map<Value*, IndexMap> type;
  195. static type build(const Graph& g, const IndexMap& index, boost::scoped_array<Value>& array_holder) {
  196. array_holder.reset(new Value[num_vertices(g)]);
  197. std::fill(array_holder.get(), array_holder.get() + num_vertices(g), Value());
  198. return make_iterator_property_map(array_holder.get(), index);
  199. }
  200. };
  201. template <class Graph, class IndexMap, class Value>
  202. struct vertex_property_map_generator_helper<Graph, IndexMap, Value, false> {
  203. typedef boost::vector_property_map<Value, IndexMap> type;
  204. static type build(const Graph& g, const IndexMap& index, boost::scoped_array<Value>& array_holder) {
  205. return boost::make_vector_property_map<Value>(index);
  206. }
  207. };
  208. template <class Graph, class IndexMap, class Value>
  209. struct vertex_property_map_generator {
  210. typedef boost::is_base_and_derived<
  211. boost::vertex_list_graph_tag,
  212. typename boost::graph_traits<Graph>::traversal_category>
  213. known_num_vertices;
  214. typedef vertex_property_map_generator_helper<Graph, IndexMap, Value, known_num_vertices::value> helper;
  215. typedef typename helper::type type;
  216. static type build(const Graph& g, const IndexMap& index, boost::scoped_array<Value>& array_holder) {
  217. return helper::build(g, index, array_holder);
  218. }
  219. };
  220. }
  221. namespace detail {
  222. template <class Graph, class IndexMap, bool KnownNumVertices>
  223. struct default_color_map_generator_helper {};
  224. template <class Graph, class IndexMap>
  225. struct default_color_map_generator_helper<Graph, IndexMap, true> {
  226. typedef boost::two_bit_color_map<IndexMap> type;
  227. static type build(const Graph& g, const IndexMap& index) {
  228. size_t nv = num_vertices(g);
  229. return boost::two_bit_color_map<IndexMap>(nv, index);
  230. }
  231. };
  232. template <class Graph, class IndexMap>
  233. struct default_color_map_generator_helper<Graph, IndexMap, false> {
  234. typedef boost::vector_property_map<boost::two_bit_color_type, IndexMap> type;
  235. static type build(const Graph& g, const IndexMap& index) {
  236. return boost::make_vector_property_map<boost::two_bit_color_type>(index);
  237. }
  238. };
  239. template <class Graph, class IndexMap>
  240. struct default_color_map_generator {
  241. typedef boost::is_base_and_derived<
  242. boost::vertex_list_graph_tag,
  243. typename boost::graph_traits<Graph>::traversal_category>
  244. known_num_vertices;
  245. typedef default_color_map_generator_helper<Graph, IndexMap, known_num_vertices::value> helper;
  246. typedef typename helper::type type;
  247. static type build(const Graph& g, const IndexMap& index) {
  248. return helper::build(g, index);
  249. }
  250. };
  251. }
  252. // Call breadth first search with default color map.
  253. template <class Graph, class SourceInputIter, class DijkstraVisitor,
  254. class PredecessorMap, class DistanceMap,
  255. class WeightMap, class IndexMap, class Compare, class Combine,
  256. class DistZero>
  257. inline void
  258. dijkstra_shortest_paths_no_init
  259. (const Graph& g,
  260. SourceInputIter s_begin, SourceInputIter s_end,
  261. PredecessorMap predecessor, DistanceMap distance, WeightMap weight,
  262. IndexMap index_map,
  263. Compare compare, Combine combine, DistZero zero,
  264. DijkstraVisitor vis)
  265. {
  266. typedef
  267. detail::default_color_map_generator<Graph, IndexMap>
  268. ColorMapHelper;
  269. typedef typename ColorMapHelper::type ColorMap;
  270. ColorMap color =
  271. ColorMapHelper::build(g, index_map);
  272. dijkstra_shortest_paths_no_init( g, s_begin, s_end, predecessor, distance, weight,
  273. index_map, compare, combine, zero, vis,
  274. color);
  275. }
  276. // Call breadth first search with default color map.
  277. template <class Graph, class DijkstraVisitor,
  278. class PredecessorMap, class DistanceMap,
  279. class WeightMap, class IndexMap, class Compare, class Combine,
  280. class DistZero>
  281. inline void
  282. dijkstra_shortest_paths_no_init
  283. (const Graph& g,
  284. typename graph_traits<Graph>::vertex_descriptor s,
  285. PredecessorMap predecessor, DistanceMap distance, WeightMap weight,
  286. IndexMap index_map,
  287. Compare compare, Combine combine, DistZero zero,
  288. DijkstraVisitor vis)
  289. {
  290. dijkstra_shortest_paths_no_init(g, &s, &s + 1, predecessor, distance,
  291. weight, index_map, compare, combine, zero,
  292. vis);
  293. }
  294. // Call breadth first search
  295. template <class Graph, class SourceInputIter, class DijkstraVisitor,
  296. class PredecessorMap, class DistanceMap,
  297. class WeightMap, class IndexMap, class Compare, class Combine,
  298. class DistZero, class ColorMap>
  299. inline void
  300. dijkstra_shortest_paths_no_init
  301. (const Graph& g,
  302. SourceInputIter s_begin, SourceInputIter s_end,
  303. PredecessorMap predecessor, DistanceMap distance, WeightMap weight,
  304. IndexMap index_map,
  305. Compare compare, Combine combine, DistZero zero,
  306. DijkstraVisitor vis, ColorMap color)
  307. {
  308. typedef indirect_cmp<DistanceMap, Compare> IndirectCmp;
  309. IndirectCmp icmp(distance, compare);
  310. typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
  311. // Now the default: use a d-ary heap
  312. boost::scoped_array<std::size_t> index_in_heap_map_holder;
  313. typedef
  314. detail::vertex_property_map_generator<Graph, IndexMap, std::size_t>
  315. IndexInHeapMapHelper;
  316. typedef typename IndexInHeapMapHelper::type IndexInHeapMap;
  317. IndexInHeapMap index_in_heap =
  318. IndexInHeapMapHelper::build(g, index_map, index_in_heap_map_holder);
  319. typedef d_ary_heap_indirect<Vertex, 4, IndexInHeapMap, DistanceMap, Compare>
  320. MutableQueue;
  321. MutableQueue Q(distance, index_in_heap, compare);
  322. detail::dijkstra_bfs_visitor<DijkstraVisitor, MutableQueue, WeightMap,
  323. PredecessorMap, DistanceMap, Combine, Compare>
  324. bfs_vis(vis, Q, weight, predecessor, distance, combine, compare, zero);
  325. breadth_first_visit(g, s_begin, s_end, Q, bfs_vis, color);
  326. }
  327. // Call breadth first search
  328. template <class Graph, class DijkstraVisitor,
  329. class PredecessorMap, class DistanceMap,
  330. class WeightMap, class IndexMap, class Compare, class Combine,
  331. class DistZero, class ColorMap>
  332. inline void
  333. dijkstra_shortest_paths_no_init
  334. (const Graph& g,
  335. typename graph_traits<Graph>::vertex_descriptor s,
  336. PredecessorMap predecessor, DistanceMap distance, WeightMap weight,
  337. IndexMap index_map,
  338. Compare compare, Combine combine, DistZero zero,
  339. DijkstraVisitor vis, ColorMap color)
  340. {
  341. dijkstra_shortest_paths_no_init(g, &s, &s + 1, predecessor, distance,
  342. weight, index_map, compare, combine,
  343. zero, vis, color);
  344. }
  345. // Initialize distances and call breadth first search with default color map
  346. template <class VertexListGraph, class SourceInputIter, class DijkstraVisitor,
  347. class PredecessorMap, class DistanceMap,
  348. class WeightMap, class IndexMap, class Compare, class Combine,
  349. class DistInf, class DistZero, typename T, typename Tag,
  350. typename Base>
  351. inline void
  352. dijkstra_shortest_paths
  353. (const VertexListGraph& g,
  354. SourceInputIter s_begin, SourceInputIter s_end,
  355. PredecessorMap predecessor, DistanceMap distance, WeightMap weight,
  356. IndexMap index_map,
  357. Compare compare, Combine combine, DistInf inf, DistZero zero,
  358. DijkstraVisitor vis,
  359. const bgl_named_params<T, Tag, Base>&
  360. BOOST_GRAPH_ENABLE_IF_MODELS_PARM(VertexListGraph,vertex_list_graph_tag))
  361. {
  362. boost::two_bit_color_map<IndexMap> color(num_vertices(g), index_map);
  363. dijkstra_shortest_paths(g, s_begin, s_end, predecessor, distance, weight,
  364. index_map, compare, combine, inf, zero, vis,
  365. color);
  366. }
  367. // Initialize distances and call breadth first search with default color map
  368. template <class VertexListGraph, class DijkstraVisitor,
  369. class PredecessorMap, class DistanceMap,
  370. class WeightMap, class IndexMap, class Compare, class Combine,
  371. class DistInf, class DistZero, typename T, typename Tag,
  372. typename Base>
  373. inline void
  374. dijkstra_shortest_paths
  375. (const VertexListGraph& g,
  376. typename graph_traits<VertexListGraph>::vertex_descriptor s,
  377. PredecessorMap predecessor, DistanceMap distance, WeightMap weight,
  378. IndexMap index_map,
  379. Compare compare, Combine combine, DistInf inf, DistZero zero,
  380. DijkstraVisitor vis,
  381. const bgl_named_params<T, Tag, Base>&
  382. BOOST_GRAPH_ENABLE_IF_MODELS_PARM(VertexListGraph,vertex_list_graph_tag))
  383. {
  384. dijkstra_shortest_paths(g, &s, &s + 1, predecessor, distance, weight,
  385. index_map, compare, combine, inf, zero, vis);
  386. }
  387. // Initialize distances and call breadth first search
  388. template <class VertexListGraph, class SourceInputIter, class DijkstraVisitor,
  389. class PredecessorMap, class DistanceMap,
  390. class WeightMap, class IndexMap, class Compare, class Combine,
  391. class DistInf, class DistZero, class ColorMap>
  392. inline void
  393. dijkstra_shortest_paths
  394. (const VertexListGraph& g,
  395. SourceInputIter s_begin, SourceInputIter s_end,
  396. PredecessorMap predecessor, DistanceMap distance, WeightMap weight,
  397. IndexMap index_map,
  398. Compare compare, Combine combine, DistInf inf, DistZero zero,
  399. DijkstraVisitor vis, ColorMap color)
  400. {
  401. typedef typename property_traits<ColorMap>::value_type ColorValue;
  402. typedef color_traits<ColorValue> Color;
  403. typename graph_traits<VertexListGraph>::vertex_iterator ui, ui_end;
  404. for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) {
  405. vis.initialize_vertex(*ui, g);
  406. put(distance, *ui, inf);
  407. put(predecessor, *ui, *ui);
  408. put(color, *ui, Color::white());
  409. }
  410. for (SourceInputIter it = s_begin; it != s_end; ++it) {
  411. put(distance, *it, zero);
  412. }
  413. dijkstra_shortest_paths_no_init(g, s_begin, s_end, predecessor, distance,
  414. weight, index_map, compare, combine, zero, vis,
  415. color);
  416. }
  417. // Initialize distances and call breadth first search
  418. template <class VertexListGraph, class DijkstraVisitor,
  419. class PredecessorMap, class DistanceMap,
  420. class WeightMap, class IndexMap, class Compare, class Combine,
  421. class DistInf, class DistZero, class ColorMap>
  422. inline void
  423. dijkstra_shortest_paths
  424. (const VertexListGraph& g,
  425. typename graph_traits<VertexListGraph>::vertex_descriptor s,
  426. PredecessorMap predecessor, DistanceMap distance, WeightMap weight,
  427. IndexMap index_map,
  428. Compare compare, Combine combine, DistInf inf, DistZero zero,
  429. DijkstraVisitor vis, ColorMap color)
  430. {
  431. dijkstra_shortest_paths(g, &s, &s + 1, predecessor, distance, weight,
  432. index_map, compare, combine, inf, zero,
  433. vis, color);
  434. }
  435. // Initialize distances and call breadth first search
  436. template <class VertexListGraph, class SourceInputIter,
  437. class DijkstraVisitor,
  438. class PredecessorMap, class DistanceMap,
  439. class WeightMap, class IndexMap, class Compare, class Combine,
  440. class DistInf, class DistZero>
  441. inline void
  442. dijkstra_shortest_paths
  443. (const VertexListGraph& g,
  444. SourceInputIter s_begin, SourceInputIter s_end,
  445. PredecessorMap predecessor, DistanceMap distance, WeightMap weight,
  446. IndexMap index_map,
  447. Compare compare, Combine combine, DistInf inf, DistZero zero,
  448. DijkstraVisitor vis)
  449. {
  450. dijkstra_shortest_paths(g, s_begin, s_end, predecessor, distance,
  451. weight, index_map,
  452. compare, combine, inf, zero, vis,
  453. no_named_parameters());
  454. }
  455. // Initialize distances and call breadth first search
  456. template <class VertexListGraph, class DijkstraVisitor,
  457. class PredecessorMap, class DistanceMap,
  458. class WeightMap, class IndexMap, class Compare, class Combine,
  459. class DistInf, class DistZero>
  460. inline void
  461. dijkstra_shortest_paths
  462. (const VertexListGraph& g,
  463. typename graph_traits<VertexListGraph>::vertex_descriptor s,
  464. PredecessorMap predecessor, DistanceMap distance, WeightMap weight,
  465. IndexMap index_map,
  466. Compare compare, Combine combine, DistInf inf, DistZero zero,
  467. DijkstraVisitor vis)
  468. {
  469. dijkstra_shortest_paths(g, &s, &s + 1, predecessor, distance,
  470. weight, index_map,
  471. compare, combine, inf, zero, vis);
  472. }
  473. namespace detail {
  474. // Handle defaults for PredecessorMap and
  475. // Distance Compare, Combine, Inf and Zero
  476. template <class VertexListGraph, class DistanceMap, class WeightMap,
  477. class IndexMap, class Params>
  478. inline void
  479. dijkstra_dispatch2
  480. (const VertexListGraph& g,
  481. typename graph_traits<VertexListGraph>::vertex_descriptor s,
  482. DistanceMap distance, WeightMap weight, IndexMap index_map,
  483. const Params& params)
  484. {
  485. // Default for predecessor map
  486. dummy_property_map p_map;
  487. typedef typename property_traits<DistanceMap>::value_type D;
  488. D inf = choose_param(get_param(params, distance_inf_t()),
  489. (std::numeric_limits<D>::max)());
  490. dijkstra_shortest_paths
  491. (g, s,
  492. choose_param(get_param(params, vertex_predecessor), p_map),
  493. distance, weight, index_map,
  494. choose_param(get_param(params, distance_compare_t()),
  495. std::less<D>()),
  496. choose_param(get_param(params, distance_combine_t()),
  497. std::plus<D>()),
  498. inf,
  499. choose_param(get_param(params, distance_zero_t()),
  500. D()),
  501. choose_param(get_param(params, graph_visitor),
  502. make_dijkstra_visitor(null_visitor())),
  503. params);
  504. }
  505. template <class VertexListGraph, class DistanceMap, class WeightMap,
  506. class IndexMap, class Params>
  507. inline void
  508. dijkstra_dispatch1
  509. (const VertexListGraph& g,
  510. typename graph_traits<VertexListGraph>::vertex_descriptor s,
  511. DistanceMap distance, WeightMap weight, IndexMap index_map,
  512. const Params& params)
  513. {
  514. // Default for distance map
  515. typedef typename property_traits<WeightMap>::value_type D;
  516. typename std::vector<D>::size_type
  517. n = is_default_param(distance) ? num_vertices(g) : 1;
  518. std::vector<D> distance_map(n);
  519. detail::dijkstra_dispatch2
  520. (g, s, choose_param(distance, make_iterator_property_map
  521. (distance_map.begin(), index_map,
  522. distance_map[0])),
  523. weight, index_map, params);
  524. }
  525. } // namespace detail
  526. // Named Parameter Variant
  527. template <class VertexListGraph, class Param, class Tag, class Rest>
  528. inline void
  529. dijkstra_shortest_paths
  530. (const VertexListGraph& g,
  531. typename graph_traits<VertexListGraph>::vertex_descriptor s,
  532. const bgl_named_params<Param,Tag,Rest>& params)
  533. {
  534. // Default for edge weight and vertex index map is to ask for them
  535. // from the graph. Default for the visitor is null_visitor.
  536. detail::dijkstra_dispatch1
  537. (g, s,
  538. get_param(params, vertex_distance),
  539. choose_const_pmap(get_param(params, edge_weight), g, edge_weight),
  540. choose_const_pmap(get_param(params, vertex_index), g, vertex_index),
  541. params);
  542. }
  543. } // namespace boost
  544. #include BOOST_GRAPH_MPI_INCLUDE(<boost/graph/distributed/dijkstra_shortest_paths.hpp>)
  545. #endif // BOOST_GRAPH_DIJKSTRA_HPP