Trouble converting johnson_all_pairs to use file IO.

Hi folks, I'm trying to convert the Boost Graph Library example from a graph built in the code, to one that usses the adjacency_list_io supporto load the graph from a file. I was able to convert the dijkstra example this way, and had no problems. I'm getting a weird error when I disable GRAPH_CODE (this example is very close to the true example in the boost source distribution): test.cpp: In function `int main(int, char**)': test.cpp:44: no matching function for call to `johnson_all_pairs_shortest_paths (main(int, char**)::Graph&, int[V][V], boost::bgl_named_params<int*, boost::vertex_distance_t, boost::no_property>)' Here's the actual code;l anybody have suggestions? #include <boost/config.hpp> #include <fstream> #include <iostream> #include <iomanip> #include <vector> #include <boost/property_map.hpp> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/adjacency_list_io.hpp> #include <boost/graph/johnson_all_pairs_shortest.hpp> int main(int argc, char **argv) { using namespace boost; typedef adjacency_list<vecS, vecS, directedS, no_property, property< edge_weight_t, int, property< edge_weight2_t, int > > > Graph; typedef std::pair < int, int >Edge; #if defined GRAPH_CODE const int V = 5; Edge edge_array[] = { Edge(0, 1), Edge(0, 4), Edge(0, 2), Edge(1, 3), Edge(1, 4), Edge(2, 1), Edge(3, 2), Edge(3, 0), Edge(4, 3) }; const std::size_t E = sizeof(edge_array) / sizeof(Edge); Graph g(edge_array, edge_array + E, V); property_map < Graph, edge_weight_t >::type w = get(edge_weight, g); int weights[] = { 3, -4, 8, 1, 7, 4, -5, 2, 6 }; int *wp = weights; graph_traits < Graph >::edge_iterator e, e_end; for (boost::tie(e, e_end) = edges(g); e != e_end; ++e) w[*e] = *wp++; #else std::ifstream graph_in(argv[1]); Graph g; graph_in >> read( g ); const int V = num_vertices(g); #endif std::vector < int >d(V, (std::numeric_limits < int >::max)()); int D[V][V]; johnson_all_pairs_shortest_paths(g, D, distance_map(&d[0])); return 0; }

David E. Konerding DSD staff wrote:
Hi folks,
I'm trying to convert the Boost Graph Library example from a graph built in the code, to one that usses the adjacency_list_io supporto load the graph from a file. I was able to convert the dijkstra example this way, and had no problems.
I'm getting a weird error when I disable GRAPH_CODE (this example is very close to the true example in the boost source distribution):
test.cpp: In function `int main(int, char**)': test.cpp:44: no matching function for call to `johnson_all_pairs_shortest_paths (main(int, char**)::Graph&, int[V][V], boost::bgl_named_params<int*, boost::vertex_distance_t, boost::no_property>)'
Sorry to follow up on my own post, but I figured it out on my own :-) Inspecting the signature for the missing reference, I pondered the "int[V][V]" (the distance map parameter) and finally realized that it was having trouble with the array declaration syntax when the value was based on a non-compile time value (the number of vertices in the graph wasn't a constant at compile time in my failing case). I'm sure this is all well defined in the C++ rules, and when I built the distance map array by hand using int **, it appeared to work. Thanks, Dave
participants (2)
-
David E. Konerding
-
David E. Konerding DSD staff