From 607d86685412ba09ebd2148df92027d2b55efd05 Mon Sep 17 00:00:00 2001 From: Jeremiah Willcock Date: Fri, 28 Sep 2012 18:34:12 +0000 Subject: [PATCH] Merged Boost.Graph changes from trunk [SVN r80740] --- doc/compressed_sparse_row.html | 4 +- doc/dijkstra_shortest_paths.html | 4 +- doc/dijkstra_shortest_paths_no_color_map.html | 14 +- doc/grid_graph.html | 6 +- doc/gursoy_atun_layout.html | 9 +- doc/sorted_erdos_renyi_gen.html | 4 +- example/Jamfile.v2 | 6 +- example/subgraph_properties.cpp | 22 +- include/boost/graph/astar_search.hpp | 2 +- .../graph/compressed_sparse_row_graph.hpp | 2 +- include/boost/graph/core_numbers.hpp | 17 +- include/boost/graph/detail/d_ary_heap.hpp | 5 + .../boost/graph/detail/indexed_properties.hpp | 4 +- include/boost/graph/detail/set_adaptor.hpp | 2 +- include/boost/graph/filtered_graph.hpp | 22 +- include/boost/graph/grid_graph.hpp | 243 ++++++++---------- include/boost/graph/labeled_graph.hpp | 6 +- include/boost/graph/named_function_params.hpp | 10 +- include/boost/graph/named_graph.hpp | 2 +- include/boost/graph/properties.hpp | 8 +- include/boost/graph/relax.hpp | 28 +- include/boost/graph/reverse_graph.hpp | 8 +- include/boost/graph/undirected_graph.hpp | 5 - include/boost/graph/visitors.hpp | 4 +- include/boost/pending/indirect_cmp.hpp | 5 +- include/boost/pending/property.hpp | 84 ++---- test/grid_graph_cc.cpp | 19 +- test/grid_graph_test.cpp | 63 +++-- 28 files changed, 276 insertions(+), 332 deletions(-) diff --git a/doc/compressed_sparse_row.html b/doc/compressed_sparse_row.html index 8850822d..976e76b9 100644 --- a/doc/compressed_sparse_row.html +++ b/doc/compressed_sparse_row.html @@ -101,8 +101,8 @@ function address(host, user) {
 namespace boost {
 
-template<typename Directed = directedS, typename VertexProperty = void, 
-         typename EdgeProperty = void, typename GraphProperty = no_property, 
+template<typename Directed = directedS, typename VertexProperty = no_property, 
+         typename EdgeProperty = no_property, typename GraphProperty = no_property, 
          typename Vertex = std::size_t, typename EdgeIndex = Vertex>
 class compressed_sparse_row_graph
 {
diff --git a/doc/dijkstra_shortest_paths.html b/doc/dijkstra_shortest_paths.html
index 4ed19711..369e78a0 100644
--- a/doc/dijkstra_shortest_paths.html
+++ b/doc/dijkstra_shortest_paths.html
@@ -330,7 +330,9 @@ IN: distance_inf(D inf)
 
The inf object must be the greatest value of any D object. That is, compare(d, inf) == true for any d != inf. - The type D is the value type of the DistanceMap.
+ The type D is the value type of the DistanceMap. Edges + are assumed to have a weight less than (using distance_compare for + comparison) this value.
Default: std::numeric_limits<D>::max()
Python: Unsupported parameter. diff --git a/doc/dijkstra_shortest_paths_no_color_map.html b/doc/dijkstra_shortest_paths_no_color_map.html index e1cc1c8e..b65d333f 100644 --- a/doc/dijkstra_shortest_paths_no_color_map.html +++ b/doc/dijkstra_shortest_paths_no_color_map.html @@ -69,7 +69,7 @@ Algorithms for some background to the shortest-path problem.

- dijkstra_shortest_paths_no_color_map differs from the original dijkstra_shortest_paths algorithm by not using a color map to identify vertices as discovered or undiscovered. Instead, this is done with the distance map: a vertex u such that distance_compare(distance_map[u], distance_infinity) == false is considered to be undiscovered. + dijkstra_shortest_paths_no_color_map differs from the original dijkstra_shortest_paths algorithm by not using a color map to identify vertices as discovered or undiscovered. Instead, this is done with the distance map: a vertex u such that distance_compare(distance_map[u], distance_infinity) == false is considered to be undiscovered. Note that this means that edges with infinite weight will not work correctly in this algorithm.

@@ -116,10 +116,6 @@ indicated by the labels on the right.

 DIJKSTRA(G, s, w)
-  for each vertex u in V (This loop is not run in dijkstra_shortest_paths_no_color_map_no_init)
-    d[u] := infinity 
-    p[u] := u 
-  end for
   d[s] := 0 
   INSERT(Q, s)
   while (Q != Ø)
@@ -141,10 +137,6 @@ DIJKSTRA(G, s, w)
 
 
 
-initialize vertex u
-
-
-
 
 discover vertex s
 
@@ -293,7 +285,9 @@ IN: distance_inf(D distance_infinity)
 
The distance_infinity object must be the greatest value of any D object. That is, distance_compare(d, distance_infinity) == true for any d != distance_infinity. - The type D is the value type of the DistanceMap.
+ The type D is the value type of the DistanceMap. All edges + are assumed to have weight less than (by distance_compare) this + value.
Default: std::numeric_limits<D>::max()
diff --git a/doc/grid_graph.html b/doc/grid_graph.html index 100c97ec..0a2fea5d 100644 --- a/doc/grid_graph.html +++ b/doc/grid_graph.html @@ -81,13 +81,13 @@
  • - Dimensions - Number of dimensions in the graph, must be greater than 2 + Dimensions - Number of dimensions in the graph
  • - VertexIndex - Type used for vertex indices, defaults to std::size_t + VertexIndex - Type used for vertex indices, defaults to std::size_t
  • - EdgeIndex - Type used for edge indices, defaults to the same type as VertexIndex + EdgeIndex - Type used for edge indices, defaults to the same type as VertexIndex
diff --git a/doc/gursoy_atun_layout.html b/doc/gursoy_atun_layout.html index 52482a36..db61443e 100644 --- a/doc/gursoy_atun_layout.html +++ b/doc/gursoy_atun_layout.html @@ -161,7 +161,8 @@ IN: double learning_constant_final IN: VertexIndexMap vertex_index_map
This maps each vertex to an integer in the range [0, - num_vertices(g)). + num_vertices(g)). This is only necessary when no + displacement map is provided. The type VertexIndexMap must be a model of Readable Property Map. The value type of the map must be an integer type. The @@ -176,9 +177,7 @@ IN: VertexIndexMap vertex_index_map IN: EdgeWeightMap weight
- This maps each edge to an weight. - num_vertices(g)). This is only necessary when no - displacement map is provided. + This maps each edge to a weight. The type EdgeWeightMap must be a model of Readable Property Map. The value type of the map must be an floating-point type @@ -221,7 +220,7 @@ Equivalent to the non-named vertex_index_map parameter.
Default: get(vertex_index, g) Note: if you use this default, make sure your graph has an internal vertex_index property. For example, - adjacenty_list with VertexList=listS does + adjacency_list with VertexList=listS does not have an internal vertex_index property.
diff --git a/doc/sorted_erdos_renyi_gen.html b/doc/sorted_erdos_renyi_gen.html index 55273fa2..b61242a5 100644 --- a/doc/sorted_erdos_renyi_gen.html +++ b/doc/sorted_erdos_renyi_gen.html @@ -63,7 +63,7 @@ graphs, suitable for initializing an adjacency_list or other graph structure with iterator-based initialization. An Erdös-Renyi graph G = (n, p) is a graph with n vertices -that. The probability of having an edge (u, v) in G +such that the probability of having an edge (u, v) in G is p for any vertices u and v. Typically, there are no self-loops, but the generator can optionally introduce self-loops with probability p.

@@ -93,7 +93,7 @@ sorted_erdos_renyi_iterator(RandomGenerator& gen, vertices_size_type n, Constructs an Erdös-Renyi generator iterator that creates a graph with n vertices and a given probability of the total number of edges that a simple graph may have. -probability. Random vertices and edges are selected using the +Random vertices and edges are selected using the random number generator gen. Self-loops are permitted only when allow_self_loops is true.
diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index 8a0c2c7d..5d4dc7f0 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -35,9 +35,11 @@ exe bfs-example : bfs-example.cpp ; exe bfs-example2 : bfs-example2.cpp ; exe dfs-example : dfs-example.cpp ; exe adjacency_list_io : adjacency_list_io.cpp ; -exe strong_components : strong_components.cpp ../build//boost_graph ; -exe strong-components : strong-components.cpp ; exe undirected_adjacency_list : undirected_adjacency_list.cpp ; exe directed_graph : directed_graph.cpp ; exe undirected_graph : undirected_graph.cpp ; exe two_graphs_common_spanning_trees : two_graphs_common_spanning_trees.cpp ; +exe strong_components : strong_components.cpp ../build//boost_graph ; +exe strong-components : strong-components.cpp ; +exe subgraph : subgraph.cpp ; +exe subgraph_properties : subgraph_properties.cpp ; diff --git a/example/subgraph_properties.cpp b/example/subgraph_properties.cpp index 7de21cec..613d53a3 100644 --- a/example/subgraph_properties.cpp +++ b/example/subgraph_properties.cpp @@ -69,20 +69,20 @@ int main(int,char*[]) std::cout << std::endl << "After initializing properties for G1:" << std::endl; std::cout << " Global and local properties for vertex G0[C]..." << std::endl; - std::cout << " G0[C]= " << boost::get(vertex_name, G0, C) << std::endl;// prints: "G0[C]= C" - std::cout << " G1[A1]= " << boost::get(vertex_name, G1, A1) << std::endl;// prints: "G1[A1]= A1" + std::cout << " G0[C]= " << boost::get(vertex_name, G0, vertex(C, G0)) << std::endl;// prints: "G0[C]= C" + std::cout << " G1[A1]= " << boost::get(vertex_name, G1, vertex(A1, G1)) << std::endl;// prints: "G1[A1]= A1" name1[B1] = "B1"; std::cout << " Global and local properties for vertex G0[E]..." << std::endl; - std::cout << " G0[E]= " << boost::get(vertex_name, G0, E) << std::endl;// prints: "G0[E]= E" - std::cout << " G1[B1]= " << boost::get(vertex_name, G1, B1) << std::endl;// prints: "G1[B1]= B1" + std::cout << " G0[E]= " << boost::get(vertex_name, G0, vertex(E, G0)) << std::endl;// prints: "G0[E]= E" + std::cout << " G1[B1]= " << boost::get(vertex_name, G1, vertex(B1, G1)) << std::endl;// prints: "G1[B1]= B1" name1[C1] = "C1"; std::cout << " Global and local properties for vertex G0[F]..." << std::endl; - std::cout << " G0[F]= " << boost::get(vertex_name, G0, F) << std::endl;// prints: "G0[F]= F" - std::cout << " G1[C1]= " << boost::get(vertex_name, G1, C1) << std::endl;// prints: "G1[C1]= C1" + std::cout << " G0[F]= " << boost::get(vertex_name, G0, vertex(F, G0)) << std::endl;// prints: "G0[F]= F" + std::cout << " G1[C1]= " << boost::get(vertex_name, G1, vertex(C1, G1)) << std::endl;// prints: "G1[C1]= C1" Graph& G2 = G0.create_subgraph(); enum { A2, B2 }; // for conveniently refering to vertices in G2 @@ -95,15 +95,15 @@ int main(int,char*[]) std::cout << std::endl << std::endl << "After initializing properties for G2:" << std::endl; std::cout << " Global and local properties for vertex G0[A]" << std::endl; - std::cout << " G0[A]= " << boost::get(vertex_name, G0, A) << std::endl;// prints: "G0[A]= A" - std::cout << " G2[A2]= " << boost::get(vertex_name, G2, A2) << std::endl;// prints: "G2[A2]= A2" + std::cout << " G0[A]= " << boost::get(vertex_name, G0, vertex(A, G0)) << std::endl;// prints: "G0[A]= A" + std::cout << " G2[A2]= " << boost::get(vertex_name, G2, vertex(A2, G2)) << std::endl;// prints: "G2[A2]= A2" name2[B2] = "B2"; std::cout << " Global and local properties for vertex G0[C]..." << std::endl; - std::cout << " G0[C]= " << boost::get(vertex_name, G0, C) << std::endl;// prints: "G0[C]= C" - std::cout << " G1[A1]= " << boost::get(vertex_name, G1, A1) << std::endl;// prints: "G1[A1]= A1" - std::cout << " G2[B2]= " << boost::get(vertex_name, G2, B2) << std::endl;// prints: "G2[B2]= B2" + std::cout << " G0[C]= " << boost::get(vertex_name, G0, vertex(C, G0)) << std::endl;// prints: "G0[C]= C" + std::cout << " G1[A1]= " << boost::get(vertex_name, G1, vertex(A1, G1)) << std::endl;// prints: "G1[A1]= A1" + std::cout << " G2[B2]= " << boost::get(vertex_name, G2, vertex(B2, G2)) << std::endl;// prints: "G2[B2]= B2" return 0; } diff --git a/include/boost/graph/astar_search.hpp b/include/boost/graph/astar_search.hpp index 132dca02..38224a98 100644 --- a/include/boost/graph/astar_search.hpp +++ b/include/boost/graph/astar_search.hpp @@ -370,8 +370,8 @@ namespace boost { detail::make_property_map_from_arg_pack_gen(D())(g, arg_pack), detail::make_property_map_from_arg_pack_gen(D())(g, arg_pack), detail::override_const_property(arg_pack, _weight_map, g, edge_weight), - detail::override_const_property(arg_pack, _vertex_index_map, g, vertex_index), detail::make_color_map_from_arg_pack(g, arg_pack), + detail::override_const_property(arg_pack, _vertex_index_map, g, vertex_index), arg_pack[_distance_compare | std::less()], arg_pack[_distance_combine | closed_plus(inf)], inf, diff --git a/include/boost/graph/compressed_sparse_row_graph.hpp b/include/boost/graph/compressed_sparse_row_graph.hpp index 59e8bb4a..42e2419a 100644 --- a/include/boost/graph/compressed_sparse_row_graph.hpp +++ b/include/boost/graph/compressed_sparse_row_graph.hpp @@ -136,7 +136,7 @@ namespace detail { typedef boost::iterator_facade, T, std::random_access_iterator_tag, const T&> base_type; T saved_value; const T& dereference() const {return saved_value;} - bool equal(default_construct_iterator i) const {return true;} + bool equal(default_construct_iterator /*i*/) const {return true;} void increment() {} void decrement() {} void advance(typename base_type::difference_type) {} diff --git a/include/boost/graph/core_numbers.hpp b/include/boost/graph/core_numbers.hpp index 3db59c72..33764c4f 100644 --- a/include/boost/graph/core_numbers.hpp +++ b/include/boost/graph/core_numbers.hpp @@ -11,8 +11,7 @@ #ifndef BOOST_GRAPH_CORE_NUMBERS_HPP #define BOOST_GRAPH_CORE_NUMBERS_HPP -#include -#include +#include #include #include #include @@ -159,7 +158,8 @@ namespace boost { if (get(c,u) > v_cn) { // remove the edge put(c,u,get(c,u)-get(wm,*oi)); - Q.update(u); + if (Q.contains(u)) + Q.update(u); } } vis.finish_vertex(v,g); @@ -175,13 +175,14 @@ namespace boost { { typedef typename property_traits::value_type D; typedef std::less Cmp; - typedef indirect_cmp IndirectCmp; - IndirectCmp icmp(c, Cmp()); // build the mutable queue typedef typename graph_traits::vertex_descriptor vertex; - typedef mutable_queue, IndirectCmp, - IndexMap> MutableQueue; - MutableQueue Q(num_vertices(g), icmp, im); + std::vector index_in_heap_data(num_vertices(g)); + typedef iterator_property_map::iterator, IndexMap> + index_in_heap_map_type; + index_in_heap_map_type index_in_heap_map(index_in_heap_data.begin(), im); + typedef d_ary_heap_indirect MutableQueue; + MutableQueue Q(c, index_in_heap_map, Cmp()); typename graph_traits::vertex_iterator vi,vi_end; for (boost::tie(vi,vi_end) = vertices(g); vi!=vi_end; ++vi) { Q.push(*vi); diff --git a/include/boost/graph/detail/d_ary_heap.hpp b/include/boost/graph/detail/d_ary_heap.hpp index ba58647a..2d921926 100644 --- a/include/boost/graph/detail/d_ary_heap.hpp +++ b/include/boost/graph/detail/d_ary_heap.hpp @@ -20,6 +20,11 @@ #include #include +// WARNING: it is not safe to copy a d_ary_heap_indirect and then modify one of +// the copies. The class is required to be copyable so it can be passed around +// (without move support from C++11), but it deep-copies the heap contents yet +// shallow-copies the index_in_heap_map. + namespace boost { // Swap two elements in a property map without assuming they model diff --git a/include/boost/graph/detail/indexed_properties.hpp b/include/boost/graph/detail/indexed_properties.hpp index e1f874b2..4494625c 100644 --- a/include/boost/graph/detail/indexed_properties.hpp +++ b/include/boost/graph/detail/indexed_properties.hpp @@ -253,7 +253,7 @@ class indexed_edge_properties typedef secret const_edge_map_type; secret operator[](secret) { return secret(); } - void write_by_index(std::size_t idx, const no_property& prop) {} + void write_by_index(std::size_t /*idx*/, const no_property& /*prop*/) {} edge_map_type get_edge_bundle(const IndexMap& = IndexMap()) const { return edge_map_type(); @@ -270,7 +270,7 @@ class indexed_edge_properties public: void push_back(const edge_push_back_type&) { } - void move_range(std::size_t src_begin, std::size_t src_end, std::size_t dest_begin) {} + void move_range(std::size_t /*src_begin*/, std::size_t /*src_end*/, std::size_t /*dest_begin*/) {} typedef dummy_no_property_iterator iterator; iterator begin() {return dummy_no_property_iterator();} diff --git a/include/boost/graph/detail/set_adaptor.hpp b/include/boost/graph/detail/set_adaptor.hpp index 90a64a2c..33acc07e 100644 --- a/include/boost/graph/detail/set_adaptor.hpp +++ b/include/boost/graph/detail/set_adaptor.hpp @@ -111,7 +111,7 @@ namespace boost { // Shit, can't implement this without knowing the size of the // universe. template - void set_compliment(const std::set& x, + void set_compliment(const std::set& /*x*/, std::set& z) { z.clear(); diff --git a/include/boost/graph/filtered_graph.hpp b/include/boost/graph/filtered_graph.hpp index 66cead60..74fea461 100644 --- a/include/boost/graph/filtered_graph.hpp +++ b/include/boost/graph/filtered_graph.hpp @@ -195,7 +195,6 @@ namespace boost { typedef filtered_graph_tag graph_tag; -#ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES // Bundled properties support template typename graph::detail::bundled_result::type& @@ -206,11 +205,10 @@ namespace boost { typename graph::detail::bundled_result::type const& operator[](Descriptor x) const { return this->m_g[x]; } -#endif // BOOST_GRAPH_NO_BUNDLED_PROPERTIES static vertex_descriptor null_vertex() { - return Graph::null_vertex(); + return Traits::null_vertex(); } //private: @@ -222,26 +220,21 @@ namespace boost { template - struct vertex_property_type > { - typedef typename vertex_property_type::type type; - }; + struct vertex_property_type >: + vertex_property_type {}; template - struct edge_property_type > { - typedef typename edge_property_type::type type; - }; + struct edge_property_type >: + edge_property_type {}; template - struct graph_property_type > { - typedef typename graph_property_type::type type; - }; + struct graph_property_type >: + graph_property_type {}; - -#ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES template struct vertex_bundle_type > @@ -256,7 +249,6 @@ namespace boost { struct graph_bundle_type > : graph_bundle_type { }; -#endif // BOOST_GRAPH_NO_BUNDLED_PROPERTIES //=========================================================================== // Non-member functions for the Filtered Edge Graph diff --git a/include/boost/graph/grid_graph.hpp b/include/boost/graph/grid_graph.hpp index 7bb37324..9a09fca3 100644 --- a/include/boost/graph/grid_graph.hpp +++ b/include/boost/graph/grid_graph.hpp @@ -30,11 +30,6 @@ #define BOOST_GRID_GRAPH_TYPE \ grid_graph -#define BOOST_GRID_GRAPH_TYPE_MEM typename BOOST_GRID_GRAPH_TYPE:: - -#define BOOST_GRID_GRAPH_TYPE_TD(mem) \ - typedef typename BOOST_GRID_GRAPH_TYPE::mem mem - #define BOOST_GRID_GRAPH_TRAITS_T \ typename graph_traits @@ -68,6 +63,13 @@ namespace boost { return (m_graph->index_of(key)); } + friend inline Index + get(const grid_graph_index_map& index_map, + const typename grid_graph_index_map::key_type& key) + { + return (index_map[key]); + } + protected: const Graph* m_graph; }; @@ -106,6 +108,13 @@ namespace boost { value_type operator[](const key_type& key) const { return (value_type(key.second, key.first)); } + + friend inline Descriptor + get(const grid_graph_reverse_edge_map& rev_map, + const typename grid_graph_reverse_edge_map::key_type& key) + { + return (rev_map[key]); + } }; template @@ -442,7 +451,7 @@ namespace boost { vertex_descriptor vertex_at (vertices_size_type vertex_index) const { - array vertex; + boost::array vertex; vertices_size_type index_divider = 1; for (std::size_t dimension_index = 0; @@ -532,6 +541,8 @@ namespace boost { vertex_descriptor source_vertex = source(edge, *this); vertex_descriptor target_vertex = target(edge, *this); + BOOST_ASSERT (source_vertex != target_vertex); + // Determine the dimension where the source and target vertices // differ (should only be one if this is a valid edge). std::size_t different_dimension_index = 0; @@ -732,13 +743,12 @@ namespace boost { // VertexListGraph //================ - template - friend inline std::pair - vertices(const BOOST_GRID_GRAPH_TYPE& graph) { - BOOST_GRID_GRAPH_TYPE_TD(vertex_iterator); - BOOST_GRID_GRAPH_TYPE_TD(vertex_function); - BOOST_GRID_GRAPH_TYPE_TD(vertex_index_iterator); + friend inline std::pair + vertices(const type& graph) { + typedef typename type::vertex_iterator vertex_iterator; + typedef typename type::vertex_function vertex_function; + typedef typename type::vertex_index_iterator vertex_index_iterator; return (std::make_pair (vertex_iterator(vertex_index_iterator(0), @@ -747,16 +757,14 @@ namespace boost { vertex_function(&graph)))); } - template - friend inline BOOST_GRID_GRAPH_TYPE_MEM vertices_size_type - num_vertices(const BOOST_GRID_GRAPH_TYPE& graph) { + friend inline typename type::vertices_size_type + num_vertices(const type& graph) { return (graph.num_vertices()); } - template - friend inline BOOST_GRID_GRAPH_TYPE_MEM vertex_descriptor - vertex(BOOST_GRID_GRAPH_TYPE_MEM vertices_size_type vertex_index, - const BOOST_GRID_GRAPH_TYPE& graph) { + friend inline typename type::vertex_descriptor + vertex(typename type::vertices_size_type vertex_index, + const type& graph) { return (graph.vertex_at(vertex_index)); } @@ -765,14 +773,13 @@ namespace boost { // IncidenceGraph //=============== - template - friend inline std::pair - out_edges(BOOST_GRID_GRAPH_TYPE_MEM vertex_descriptor vertex, - const BOOST_GRID_GRAPH_TYPE& graph) { - BOOST_GRID_GRAPH_TYPE_TD(degree_iterator); - BOOST_GRID_GRAPH_TYPE_TD(out_edge_function); - BOOST_GRID_GRAPH_TYPE_TD(out_edge_iterator); + friend inline std::pair + out_edges(typename type::vertex_descriptor vertex, + const type& graph) { + typedef typename type::degree_iterator degree_iterator; + typedef typename type::out_edge_function out_edge_function; + typedef typename type::out_edge_iterator out_edge_iterator; return (std::make_pair (out_edge_iterator(degree_iterator(0), @@ -781,19 +788,17 @@ namespace boost { out_edge_function(vertex, &graph)))); } - template - friend inline BOOST_GRID_GRAPH_TYPE_MEM degree_size_type + friend inline typename type::degree_size_type out_degree - (BOOST_GRID_GRAPH_TYPE_MEM vertex_descriptor vertex, - const BOOST_GRID_GRAPH_TYPE& graph) { + (typename type::vertex_descriptor vertex, + const type& graph) { return (graph.out_degree(vertex)); } - template - friend inline BOOST_GRID_GRAPH_TYPE_MEM edge_descriptor - out_edge_at(BOOST_GRID_GRAPH_TYPE_MEM vertex_descriptor vertex, - BOOST_GRID_GRAPH_TYPE_MEM degree_size_type out_edge_index, - const BOOST_GRID_GRAPH_TYPE& graph) { + friend inline typename type::edge_descriptor + out_edge_at(typename type::vertex_descriptor vertex, + typename type::degree_size_type out_edge_index, + const type& graph) { return (graph.out_edge_at(vertex, out_edge_index)); } @@ -801,14 +806,13 @@ namespace boost { // AdjacencyGraph //=============== - template - friend typename std::pair - adjacent_vertices (BOOST_GRID_GRAPH_TYPE_MEM vertex_descriptor vertex, - const BOOST_GRID_GRAPH_TYPE& graph) { - BOOST_GRID_GRAPH_TYPE_TD(degree_iterator); - BOOST_GRID_GRAPH_TYPE_TD(adjacent_vertex_function); - BOOST_GRID_GRAPH_TYPE_TD(adjacency_iterator); + friend typename std::pair + adjacent_vertices (typename type::vertex_descriptor vertex, + const type& graph) { + typedef typename type::degree_iterator degree_iterator; + typedef typename type::adjacent_vertex_function adjacent_vertex_function; + typedef typename type::adjacency_iterator adjacency_iterator; return (std::make_pair (adjacency_iterator(degree_iterator(0), @@ -821,26 +825,23 @@ namespace boost { // EdgeListGraph //============== - template - friend inline BOOST_GRID_GRAPH_TYPE_MEM edges_size_type - num_edges(const BOOST_GRID_GRAPH_TYPE& graph) { + friend inline typename type::edges_size_type + num_edges(const type& graph) { return (graph.num_edges()); } - template - friend inline BOOST_GRID_GRAPH_TYPE_MEM edge_descriptor - edge_at(BOOST_GRID_GRAPH_TYPE_MEM edges_size_type edge_index, - const BOOST_GRID_GRAPH_TYPE& graph) { + friend inline typename type::edge_descriptor + edge_at(typename type::edges_size_type edge_index, + const type& graph) { return (graph.edge_at(edge_index)); } - template - friend inline std::pair - edges(const BOOST_GRID_GRAPH_TYPE& graph) { - BOOST_GRID_GRAPH_TYPE_TD(edge_index_iterator); - BOOST_GRID_GRAPH_TYPE_TD(edge_function); - BOOST_GRID_GRAPH_TYPE_TD(edge_iterator); + friend inline std::pair + edges(const type& graph) { + typedef typename type::edge_index_iterator edge_index_iterator; + typedef typename type::edge_function edge_function; + typedef typename type::edge_iterator edge_iterator; return (std::make_pair (edge_iterator(edge_index_iterator(0), @@ -853,14 +854,13 @@ namespace boost { // BiDirectionalGraph //=================== - template - friend inline std::pair - in_edges(BOOST_GRID_GRAPH_TYPE_MEM vertex_descriptor vertex, - const BOOST_GRID_GRAPH_TYPE& graph) { - BOOST_GRID_GRAPH_TYPE_TD(in_edge_function); - BOOST_GRID_GRAPH_TYPE_TD(degree_iterator); - BOOST_GRID_GRAPH_TYPE_TD(in_edge_iterator); + friend inline std::pair + in_edges(typename type::vertex_descriptor vertex, + const type& graph) { + typedef typename type::in_edge_function in_edge_function; + typedef typename type::degree_iterator degree_iterator; + typedef typename type::in_edge_iterator in_edge_iterator; return (std::make_pair (in_edge_iterator(degree_iterator(0), @@ -869,25 +869,22 @@ namespace boost { in_edge_function(vertex, &graph)))); } - template - friend inline BOOST_GRID_GRAPH_TYPE_MEM degree_size_type - in_degree (BOOST_GRID_GRAPH_TYPE_MEM vertex_descriptor vertex, - const BOOST_GRID_GRAPH_TYPE& graph) { + friend inline typename type::degree_size_type + in_degree (typename type::vertex_descriptor vertex, + const type& graph) { return (graph.in_degree(vertex)); } - template - friend inline BOOST_GRID_GRAPH_TYPE_MEM degree_size_type - degree (BOOST_GRID_GRAPH_TYPE_MEM vertex_descriptor vertex, - const BOOST_GRID_GRAPH_TYPE& graph) { + friend inline typename type::degree_size_type + degree (typename type::vertex_descriptor vertex, + const type& graph) { return (graph.out_degree(vertex) * 2); } - template - friend inline BOOST_GRID_GRAPH_TYPE_MEM edge_descriptor - in_edge_at(BOOST_GRID_GRAPH_TYPE_MEM vertex_descriptor vertex, - BOOST_GRID_GRAPH_TYPE_MEM degree_size_type in_edge_index, - const BOOST_GRID_GRAPH_TYPE& graph) { + friend inline typename type::edge_descriptor + in_edge_at(typename type::vertex_descriptor vertex, + typename type::degree_size_type in_edge_index, + const type& graph) { return (graph.in_edge_at(vertex, in_edge_index)); } @@ -896,21 +893,20 @@ namespace boost { // Adjacency Matrix //================== - template - friend std::pair - edge (BOOST_GRID_GRAPH_TYPE_MEM vertex_descriptor source_vertex, - BOOST_GRID_GRAPH_TYPE_MEM vertex_descriptor destination_vertex, - const BOOST_GRID_GRAPH_TYPE& graph) { + friend std::pair + edge (typename type::vertex_descriptor source_vertex, + typename type::vertex_descriptor destination_vertex, + const type& graph) { - std::pair edge_exists = + std::pair edge_exists = std::make_pair(std::make_pair(source_vertex, destination_vertex), false); for (std::size_t dimension_index = 0; dimension_index < Dimensions; ++dimension_index) { - BOOST_GRID_GRAPH_TYPE_MEM vertices_size_type dim_difference = 0; - BOOST_GRID_GRAPH_TYPE_MEM vertices_size_type + typename type::vertices_size_type dim_difference = 0; + typename type::vertices_size_type source_dim = source_vertex[dimension_index], dest_dim = destination_vertex[dimension_index]; @@ -957,77 +953,54 @@ namespace boost { // Index Property Map Functions //============================= - template - friend inline BOOST_GRID_GRAPH_TYPE_MEM vertices_size_type + friend inline typename type::vertices_size_type get(vertex_index_t, - const BOOST_GRID_GRAPH_TYPE& graph, - BOOST_GRID_GRAPH_TYPE_MEM vertex_descriptor vertex) { + const type& graph, + typename type::vertex_descriptor vertex) { return (graph.index_of(vertex)); } - template - friend inline BOOST_GRID_GRAPH_TYPE_MEM edges_size_type + friend inline typename type::edges_size_type get(edge_index_t, - const BOOST_GRID_GRAPH_TYPE& graph, - BOOST_GRID_GRAPH_TYPE_MEM edge_descriptor edge) { + const type& graph, + typename type::edge_descriptor edge) { return (graph.index_of(edge)); } - template friend inline grid_graph_index_map< - BOOST_GRID_GRAPH_TYPE, - BOOST_GRID_GRAPH_TYPE_MEM vertex_descriptor, - BOOST_GRID_GRAPH_TYPE_MEM vertices_size_type> - get(vertex_index_t, const BOOST_GRID_GRAPH_TYPE& graph) { + type, + typename type::vertex_descriptor, + typename type::vertices_size_type> + get(vertex_index_t, const type& graph) { return (grid_graph_index_map< - BOOST_GRID_GRAPH_TYPE, - BOOST_GRID_GRAPH_TYPE_MEM vertex_descriptor, - BOOST_GRID_GRAPH_TYPE_MEM vertices_size_type>(graph)); + type, + typename type::vertex_descriptor, + typename type::vertices_size_type>(graph)); } - template friend inline grid_graph_index_map< - BOOST_GRID_GRAPH_TYPE, - BOOST_GRID_GRAPH_TYPE_MEM edge_descriptor, - BOOST_GRID_GRAPH_TYPE_MEM edges_size_type> - get(edge_index_t, const BOOST_GRID_GRAPH_TYPE& graph) { + type, + typename type::edge_descriptor, + typename type::edges_size_type> + get(edge_index_t, const type& graph) { return (grid_graph_index_map< - BOOST_GRID_GRAPH_TYPE, - BOOST_GRID_GRAPH_TYPE_MEM edge_descriptor, - BOOST_GRID_GRAPH_TYPE_MEM edges_size_type>(graph)); + type, + typename type::edge_descriptor, + typename type::edges_size_type>(graph)); } - template friend inline grid_graph_reverse_edge_map< - BOOST_GRID_GRAPH_TYPE_MEM edge_descriptor> - get(edge_reverse_t, const BOOST_GRID_GRAPH_TYPE& graph) { + typename type::edge_descriptor> + get(edge_reverse_t, const type& graph) { return (grid_graph_reverse_edge_map< - BOOST_GRID_GRAPH_TYPE_MEM edge_descriptor>()); + typename type::edge_descriptor>()); } - template - friend inline Index - get(const grid_graph_index_map& index_map, - const typename grid_graph_index_map::key_type& key) - { - return (index_map[key]); - } - template friend struct grid_graph_index_map; - template - friend inline Descriptor - get(const grid_graph_reverse_edge_map& rev_map, - const typename grid_graph_reverse_edge_map::key_type& key) - { - return (rev_map[key]); - } - template friend struct grid_graph_reverse_edge_map; @@ -1036,8 +1009,6 @@ namespace boost { } // namespace boost #undef BOOST_GRID_GRAPH_TYPE -#undef BOOST_GRID_GRAPH_TYPE_TD -#undef BOOST_GRID_GRAPH_TYPE_MEM #undef BOOST_GRID_GRAPH_TEMPLATE_PARAMS #undef BOOST_GRID_GRAPH_TRAITS_T diff --git a/include/boost/graph/labeled_graph.hpp b/include/boost/graph/labeled_graph.hpp index e1a2f7c2..67505d25 100644 --- a/include/boost/graph/labeled_graph.hpp +++ b/include/boost/graph/labeled_graph.hpp @@ -196,7 +196,7 @@ namespace graph_detail { { // If the element is already occupied, then we probably don't want to // overwrite it. - if(c[l] == Graph::null_vertex()) return false; + if(c[l] == graph_traits::null_vertex()) return false; c[l] = v; return true; } @@ -411,7 +411,7 @@ public: /** Return a null descriptor */ static vertex_descriptor null_vertex() - { return graph_type::null_vertex(); } + { return graph_traits::null_vertex(); } private: graph_type _graph; @@ -525,7 +525,7 @@ public: #endif static vertex_descriptor null_vertex() - { return graph_type::null_vertex(); } + { return graph_traits::null_vertex(); } private: graph_type* _graph; diff --git a/include/boost/graph/named_function_params.hpp b/include/boost/graph/named_function_params.hpp index 32dd5802..94314a69 100644 --- a/include/boost/graph/named_function_params.hpp +++ b/include/boost/graph/named_function_params.hpp @@ -432,13 +432,13 @@ BOOST_BGL_DECLARE_NAMED_PARAMS template struct override_property_t { typedef ArgType result_type; - result_type operator()(const Graph& g, const typename boost::add_reference::type a) const {return a;} + result_type operator()(const Graph&, const typename boost::add_reference::type a) const {return a;} }; template struct override_property_t { typedef typename boost::property_map::type result_type; - result_type operator()(const Graph& g, const ArgType& a) const {return get(Prop(), g);} + result_type operator()(const Graph& g, const ArgType&) const {return get(Prop(), g);} }; template @@ -455,7 +455,7 @@ BOOST_BGL_DECLARE_NAMED_PARAMS template typename override_property_result::type - override_property(const ArgPack& ap, const boost::parameter::keyword& t, const Graph& g, Prop prop) { + override_property(const ArgPack& ap, const boost::parameter::keyword& t, const Graph& g, Prop) { return override_property_t< typename boost::parameter::value_type::type, Prop, @@ -633,7 +633,7 @@ BOOST_BGL_DECLARE_NAMED_PARAMS typedef Q priority_queue_type; static priority_queue_type - make_queue(const Graph& g, const ArgPack& ap, KeyT defaultKey, const Q& q) { + make_queue(const Graph&, const ArgPack&, KeyT, const Q& q) { return q; } }; @@ -645,7 +645,7 @@ BOOST_BGL_DECLARE_NAMED_PARAMS typedef boost::d_ary_heap_indirect::helper::map_type, Compare> priority_queue_type; static priority_queue_type - make_queue(const Graph& g, const ArgPack& ap, KeyT defaultKey, const Q& q) { + make_queue(const Graph& g, const ArgPack& ap, KeyT defaultKey, const Q&) { return priority_queue_type( map_maker::make_map(g, ap, defaultKey), map_maker::make_map(g, ap, typename boost::property_traits::value_type(-1)) diff --git a/include/boost/graph/named_graph.hpp b/include/boost/graph/named_graph.hpp index f49c0970..77e1a22f 100644 --- a/include/boost/graph/named_graph.hpp +++ b/include/boost/graph/named_graph.hpp @@ -105,7 +105,7 @@ public: typedef vertex_name_type argument_type; typedef VertexProperty result_type; - VertexProperty operator()(const vertex_name_type& name) + VertexProperty operator()(const vertex_name_type&) { boost::throw_exception(std::runtime_error("add_vertex: " "unable to create a vertex from its name")); diff --git a/include/boost/graph/properties.hpp b/include/boost/graph/properties.hpp index 6b5ade97..5cc926bc 100644 --- a/include/boost/graph/properties.hpp +++ b/include/boost/graph/properties.hpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include @@ -149,13 +149,13 @@ namespace boost { template struct property_kind_from_graph { typedef typename boost::mpl::if_< - boost::is_same::type>, + boost::is_base_of::type>, vertex_property_tag, typename boost::mpl::if_< - boost::is_same::type>, + boost::is_base_of::type>, edge_property_tag, typename boost::mpl::if_< - boost::is_same::type>, + boost::is_base_of::type>, graph_property_tag, void>::type>::type>::type type; }; diff --git a/include/boost/graph/relax.hpp b/include/boost/graph/relax.hpp index 46857960..e3866df4 100644 --- a/include/boost/graph/relax.hpp +++ b/include/boost/graph/relax.hpp @@ -49,20 +49,30 @@ namespace boost { Vertex u = source(e, g), v = target(e, g); typedef typename property_traits::value_type D; typedef typename property_traits::value_type W; - D d_u = get(d, u), d_v = get(d, v); - W w_e = get(w, e); + const D d_u = get(d, u); + const D d_v = get(d, v); + const W& w_e = get(w, e); - // The redundant gets in the return statements are to ensure that extra - // floating-point precision in x87 registers does not lead to relax() - // returning true when the distance did not actually change. + // The seemingly redundant comparisons after the distance puts are to + // ensure that extra floating-point precision in x87 registers does not + // lead to relax() returning true when the distance did not actually + // change. if ( compare(combine(d_u, w_e), d_v) ) { put(d, v, combine(d_u, w_e)); - put(p, v, u); - return compare(get(d, v), d_v); + if (compare(get(d, v), d_v)) { + put(p, v, u); + return true; + } else { + return false; + } } else if (is_undirected && compare(combine(d_v, w_e), d_u)) { put(d, u, combine(d_v, w_e)); - put(p, u, v); - return compare(get(d, u), d_u); + if (compare(get(d, u), d_u)) { + put(p, u, v); + return true; + } else { + return false; + } } else return false; } diff --git a/include/boost/graph/reverse_graph.hpp b/include/boost/graph/reverse_graph.hpp index 96fc32d3..bea975ab 100644 --- a/include/boost/graph/reverse_graph.hpp +++ b/include/boost/graph/reverse_graph.hpp @@ -460,7 +460,7 @@ template typename enable_if, detail::underlying_edge_desc_map_type::edge_descriptor> >::type get(edge_underlying_t, - G& g) + G&) { return detail::underlying_edge_desc_map_type::edge_descriptor>(); } @@ -468,7 +468,7 @@ get(edge_underlying_t, template typename enable_if, typename graph_traits::edge_descriptor>::type get(edge_underlying_t, - G& g, + G&, const typename graph_traits::edge_descriptor& k) { return k.underlying_descx; @@ -477,7 +477,7 @@ get(edge_underlying_t, template typename enable_if, detail::underlying_edge_desc_map_type::edge_descriptor> >::type get(edge_underlying_t, - const G& g) + const G&) { return detail::underlying_edge_desc_map_type::edge_descriptor>(); } @@ -485,7 +485,7 @@ get(edge_underlying_t, template typename enable_if, typename graph_traits::edge_descriptor>::type get(edge_underlying_t, - const G& g, + const G&, const typename graph_traits::edge_descriptor& k) { return k.underlying_descx; diff --git a/include/boost/graph/undirected_graph.hpp b/include/boost/graph/undirected_graph.hpp index adcc86e5..738a5c95 100644 --- a/include/boost/graph/undirected_graph.hpp +++ b/include/boost/graph/undirected_graph.hpp @@ -10,11 +10,6 @@ #include #include -// NOTE: The retag_property_list is used to "normalize" a proeprty such that -// any non-property conforming parameter is wrapped in a vertex_bundle -// property. For example (with bad syntax) retag> -> property, -// but retag -> property. - namespace boost { struct undirected_graph_tag { }; diff --git a/include/boost/graph/visitors.hpp b/include/boost/graph/visitors.hpp index f986c96c..d10e140c 100644 --- a/include/boost/graph/visitors.hpp +++ b/include/boost/graph/visitors.hpp @@ -269,7 +269,7 @@ namespace boost { {} template - void operator() (VertexOrEdge v, const Graph& g) + void operator() (VertexOrEdge v, const Graph&) { put (property_map_, v, value_); } @@ -292,7 +292,7 @@ namespace boost { inline property_put put_property (PropertyMap property_map, typename property_traits ::value_type value, - EventTag tag) + EventTag) { return property_put (property_map, value); } diff --git a/include/boost/pending/indirect_cmp.hpp b/include/boost/pending/indirect_cmp.hpp index 638625ce..14ee5314 100644 --- a/include/boost/pending/indirect_cmp.hpp +++ b/include/boost/pending/indirect_cmp.hpp @@ -33,14 +33,15 @@ namespace boost { typedef typename boost::property_traits::key_type K; typedef K first_argument_type; typedef K second_argument_type; - typedef T result_type; + typedef bool result_type; inline indirect_cmp(const ReadablePropertyMap& df, const Compare& c = Compare()) : d(df), cmp(c) { } template inline bool operator()(const A& u, const B& v) const { - T du = get(d, u), dv = get(d, v); + const T& du = get(d, u); + const T& dv = get(d, v); return cmp(du, dv); } protected: diff --git a/include/boost/pending/property.hpp b/include/boost/pending/property.hpp index 93ebffbf..3053908d 100644 --- a/include/boost/pending/property.hpp +++ b/include/boost/pending/property.hpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace boost { @@ -53,8 +54,8 @@ namespace boost { enum graph_bundle_t {graph_bundle}; // Code to look up one property in a property list: - template - struct lookup_one_property_internal {BOOST_STATIC_CONSTANT(bool, found = false);}; + template + struct lookup_one_property_internal {BOOST_STATIC_CONSTANT(bool, found = false); typedef void type;}; // Special-case properties (vertex_all, edge_all, graph_all) #define BGL_ALL_PROP(tag) \ @@ -93,8 +94,14 @@ namespace boost { private: \ typedef lookup_one_property_internal base_type; \ public: \ - static typename base_type::type& lookup(property& p, BOOST_JOIN(kind, _bundle_t)) {return base_type::lookup(p.m_base, BOOST_JOIN(kind, _bundle_t)());} \ - static const typename base_type::type& lookup(const property& p, BOOST_JOIN(kind, _bundle_t)) {return base_type::lookup(p.m_base, BOOST_JOIN(kind, _bundle_t)());} \ + template \ + static typename lazy_enable_if_c<(base_type::found && (is_same::value)), \ + add_reference >::type \ + lookup(property& p, BundleTag) {return base_type::lookup(p.m_base, BOOST_JOIN(kind, _bundle_t)());} \ + template \ + static typename lazy_enable_if_c<(base_type::found && (is_same::value)), \ + add_reference >::type \ + lookup(const property& p, BundleTag) {return base_type::lookup(p.m_base, BOOST_JOIN(kind, _bundle_t)());} \ }; \ BGL_DO_ONE_BUNDLE_TYPE(vertex) @@ -122,12 +129,14 @@ namespace boost { typedef lookup_one_property_internal base_type; public: template - static typename enable_if >, typename base_type::type&>::type + static typename lazy_enable_if >, + add_reference >::type lookup(PL& prop, const PropName& tag) { return base_type::lookup(prop.m_base, tag); } template - static typename enable_if >, const typename base_type::type&>::type + static typename lazy_enable_if >, + add_reference >::type lookup(const PL& prop, const PropName& tag) { return base_type::lookup(prop.m_base, tag); } @@ -135,12 +144,12 @@ namespace boost { // Pointer-to-member access to bundled properties #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES - template - struct lookup_one_property_internal { + template + struct lookup_one_property_internal >::type> { BOOST_STATIC_CONSTANT(bool, found = true); typedef R type; - static R& lookup(T& x, R T::*ptr) {return x.*ptr;} - static const R& lookup(const T& x, R T::*ptr) {return x.*ptr;} + static R& lookup(T& x, R TMaybeBase::*ptr) {return x.*ptr;} + static const R& lookup(const T& x, R TMaybeBase::*ptr) {return x.*ptr;} }; #endif @@ -153,7 +162,8 @@ namespace boost { BOOST_STATIC_CONSTANT(bool, found = (lookup_one_property_internal::found)); typedef const typename lookup_one_property_internal::type type; template - static typename enable_if, const typename lookup_one_property_internal::type&>::type + static typename lazy_enable_if, + add_reference::type> >::type lookup(const U& p, Tag tag) { return lookup_one_property_internal::lookup(p, tag); } @@ -199,58 +209,6 @@ namespace boost { : mpl::bool_::value> { }; - /** @internal @name Retag Property List - * This metafunction is used internally to normalize a property if it is - * actually modeling a property. Specifically this is used in Boost.Graph - * to map user-provided classes into bundled properties. - */ - //@{ - // One base case of the recursive form (see below). This matches any - // retag request that does not include a property<...> or no_property as - // the FinalType. This is used for generating bundles in Boost.Graph. - template - struct retag_property_list - { - typedef property type; - typedef FinalType retagged; - }; - - // Recursively retag the nested property list. - template - struct retag_property_list > - { - private: - typedef retag_property_list next; - - public: - typedef property type; - typedef typename next::retagged retagged; - }; - - // This base case will correctly deduce the final property type if the - // retagged property is given in property form. This should not hide - // the base case below. - // NOTE: This addresses a problem of layering bundled properties in the BGL - // where multiple retaggings will fail to deduce the correct retagged - // type. - template - struct retag_property_list > - { - public: - typedef property type; - typedef FinalType retagged; - }; - - // A final base case of the retag_property_list, this will terminate a - // properly structured list. - template - struct retag_property_list - { - typedef no_property type; - typedef no_property retagged; - }; - //@} - template class lookup_one_property_f; diff --git a/test/grid_graph_cc.cpp b/test/grid_graph_cc.cpp index a9e1c808..d49de7c3 100644 --- a/test/grid_graph_cc.cpp +++ b/test/grid_graph_cc.cpp @@ -12,14 +12,13 @@ #include #include -#define DIMENSIONS 3 using namespace boost; -int main (int, char*[]) { - - typedef grid_graph Graph; - typedef graph_traits::vertex_descriptor Vertex; - typedef graph_traits::edge_descriptor Edge; +template +void check() { + typedef grid_graph Graph; + typedef typename graph_traits::vertex_descriptor Vertex; + typedef typename graph_traits::edge_descriptor Edge; BOOST_CONCEPT_ASSERT((BidirectionalGraphConcept )); BOOST_CONCEPT_ASSERT((VertexListGraphConcept )); @@ -29,6 +28,14 @@ int main (int, char*[]) { BOOST_CONCEPT_ASSERT((AdjacencyMatrixConcept )); BOOST_CONCEPT_ASSERT((ReadablePropertyGraphConcept )); BOOST_CONCEPT_ASSERT((ReadablePropertyGraphConcept )); +} + +int main (int, char*[]) { + check<0>(); + check<1>(); + check<2>(); + check<3>(); + check<4>(); return (0); } diff --git a/test/grid_graph_test.cpp b/test/grid_graph_test.cpp index 3cd665bd..d88e68d2 100644 --- a/test/grid_graph_test.cpp +++ b/test/grid_graph_test.cpp @@ -17,8 +17,6 @@ #include #include -#define DIMENSIONS 3 - using namespace boost; // Function that prints a vertex to std::cout @@ -28,11 +26,11 @@ void print_vertex(Vertex vertex_to_print) { std::cout << "("; for (std::size_t dimension_index = 0; - dimension_index < DIMENSIONS; + dimension_index < vertex_to_print.size(); ++dimension_index) { std::cout << vertex_to_print[dimension_index]; - if (dimension_index != (DIMENSIONS - 1)) { + if (dimension_index != (vertex_to_print.size() - 1)) { std::cout << ", "; } } @@ -40,31 +38,23 @@ void print_vertex(Vertex vertex_to_print) { std::cout << ")"; } -int test_main(int argc, char* argv[]) { +template +void do_test(minstd_rand& generator) { + typedef grid_graph Graph; + typedef typename graph_traits::vertices_size_type vertices_size_type; + typedef typename graph_traits::edges_size_type edges_size_type; - std::size_t random_seed = time(0); + typedef typename graph_traits::vertex_descriptor vertex_descriptor; + typedef typename graph_traits::edge_descriptor edge_descriptor; - if (argc > 1) { - random_seed = lexical_cast(argv[1]); - } - - minstd_rand generator(random_seed); - - typedef grid_graph Graph; - typedef graph_traits::vertices_size_type vertices_size_type; - typedef graph_traits::edges_size_type edges_size_type; - - typedef graph_traits::vertex_descriptor vertex_descriptor; - typedef graph_traits::edge_descriptor edge_descriptor; - - std::cout << "Dimensions: " << DIMENSIONS << ", lengths: "; + std::cout << "Dimensions: " << Dims << ", lengths: "; // Randomly generate the dimension lengths (3-10) and wrapping - array lengths; - array wrapped; + boost::array lengths; + boost::array wrapped; - for (int dimension_index = 0; - dimension_index < DIMENSIONS; + for (unsigned int dimension_index = 0; + dimension_index < Dims; ++dimension_index) { lengths[dimension_index] = 3 + (generator() % 8); wrapped[dimension_index] = ((generator() % 2) == 0); @@ -78,8 +68,8 @@ int test_main(int argc, char* argv[]) { Graph graph(lengths, wrapped); // Verify dimension lengths and wrapping - for (int dimension_index = 0; - dimension_index < DIMENSIONS; + for (unsigned int dimension_index = 0; + dimension_index < Dims; ++dimension_index) { BOOST_REQUIRE(graph.length(dimension_index) == lengths[dimension_index]); BOOST_REQUIRE(graph.wrapped(dimension_index) == wrapped[dimension_index]); @@ -107,8 +97,8 @@ int test_main(int argc, char* argv[]) { vertices_size_type current_index = get(boost::vertex_index, graph, current_vertex); - for (int dimension_index = 0; - dimension_index < DIMENSIONS; + for (unsigned int dimension_index = 0; + dimension_index < Dims; ++dimension_index) { BOOST_REQUIRE(/*(current_vertex[dimension_index] >= 0) && */ // Always true (current_vertex[dimension_index] < lengths[dimension_index])); @@ -205,6 +195,23 @@ int test_main(int argc, char* argv[]) { } BOOST_REQUIRE(edge_count == num_edges(graph)); +} + +int test_main(int argc, char* argv[]) { + + std::size_t random_seed = time(0); + + if (argc > 1) { + random_seed = lexical_cast(argv[1]); + } + + minstd_rand generator(random_seed); + + do_test<0>(generator); + do_test<1>(generator); + do_test<2>(generator); + do_test<3>(generator); + do_test<4>(generator); return (0); }