From bac69f84decd0b1b6fd81aafe1f41ed1fb1998e7 Mon Sep 17 00:00:00 2001 From: Jeremiah Willcock Date: Wed, 4 Feb 2009 20:58:15 +0000 Subject: [PATCH] Changed to two_bit_color_map by default [SVN r51020] --- .../boost/graph/dijkstra_shortest_paths.hpp | 55 +++++++++++++++---- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/include/boost/graph/dijkstra_shortest_paths.hpp b/include/boost/graph/dijkstra_shortest_paths.hpp index 97c11a8a..6233e08b 100644 --- a/include/boost/graph/dijkstra_shortest_paths.hpp +++ b/include/boost/graph/dijkstra_shortest_paths.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -182,6 +183,41 @@ namespace boost { }; } + namespace detail { + template + struct default_color_map_generator_helper {}; + + template + struct default_color_map_generator_helper { + typedef boost::two_bit_color_map type; + static type build(const Graph& g, const IndexMap& index) { + size_t nv = num_vertices(g); + return boost::two_bit_color_map(nv, index); + } + }; + + template + struct default_color_map_generator_helper { + typedef boost::vector_property_map type; + static type build(const Graph& g, const IndexMap& index) { + return make_vector_property_map(index); + } + }; + + template + struct default_color_map_generator { + typedef boost::is_base_and_derived< + boost::vertex_list_graph_tag, + typename boost::graph_traits::traversal_category> + known_num_vertices; + typedef default_color_map_generator_helper helper; + typedef typename helper::type type; + static type build(const Graph& g, const IndexMap& index) { + return helper::build(g, index); + } + }; + } + // Call breadth first search with default color map. template color_map_holder; typedef - detail::vertex_property_map_generator + detail::default_color_map_generator ColorMapHelper; typedef typename ColorMapHelper::type ColorMap; ColorMap color = - ColorMapHelper::build(g, index_map, white_color, color_map_holder); + ColorMapHelper::build(g, index_map); dijkstra_shortest_paths_no_init( g, s, predecessor, distance, weight, index_map, compare, combine, zero, vis, color); @@ -279,12 +314,10 @@ namespace boost { Compare compare, Combine combine, DistInf inf, DistZero zero, DijkstraVisitor vis) { - std::vector color(num_vertices(g)); - default_color_type c = white_color; + boost::two_bit_color_map color(num_vertices(g), index_map); dijkstra_shortest_paths(g, s, predecessor, distance, weight, index_map, compare, combine, inf, zero, vis, - make_iterator_property_map(&color[0], index_map, - c)); + color); } // Initialize distances and call breadth first search @@ -366,18 +399,16 @@ namespace boost { std::vector distance_map(n); // Default for color map - typename std::vector::size_type + typename std::vector::size_type m = is_default_param(color) ? num_vertices(g) : 1; - std::vector color_map(m); + boost::two_bit_color_map color_map(m, index_map); detail::dijkstra_dispatch2 (g, s, choose_param(distance, make_iterator_property_map (distance_map.begin(), index_map, distance_map[0])), weight, index_map, params, - choose_param(color, make_iterator_property_map - (color_map.begin(), index_map, - color_map[0]))); + choose_param(color, color_map)); } } // namespace detail