72#ifdef TEST_AGAINST_BOOST
73 typedef adjacency_list<vecS, vecS, undirectedS, no_property,
74 property< edge_weight_t, double, property< edge_weight2_t, double > > > Graph;
80 cout <<
" Test graph |V|="<<V<<
",|E|="<<E<<endl;
81 valarray<double> weights(E);
82 for(
unsigned i=0;i<E;i++) {
83 weights[i]=round((
static_cast<double>(rand())/
static_cast<double>(RAND_MAX))*10);
84#ifdef TEST_AGAINST_BOOST
85 add_edge(
es[i].first,
es[i].second,weights[i],g);
89#ifdef TEST_AGAINST_BOOST
90 vector < double >d(V, (numeric_limits < double >::max)());
91 typedef vector<double> weight_vec;
92 vector<weight_vec>
D(V,weight_vec(V));
93 cout<<
"Running boost::johnson_all_pairs_shortest_paths..."<<endl;
95 johnson_all_pairs_shortest_paths(g,
D, distance_map(&d[0]));
98 double** D1=
new double*[V];
99 for(
unsigned i=0;i<V;i++) {
102 cout<<
"Running shortest_paths::johnsons..."<<endl;
106 double** D2=
new double*[V];
107 for(
unsigned i=0;i<V;i++) {
110 cout<<
"Running shortest_paths::floyd_warshall..."<<endl;
115 for (
unsigned int i = 0; i < V; ++i) {
116 if(dump) cout << i <<
" -> ";
117 for (
unsigned int j = 0; j < V; ++j) {
118 if(dump) cout << setw(5) << D1[i][j];
119 assert(D1[i][j]==D2[i][j]);
120#ifdef TEST_AGAINST_BOOST
121 assert(
D[i][j]==D2[i][j]);
124 if(dump) cout << endl;
126#ifdef TEST_AGAINST_BOOST
128 ofstream fout(
"figs/johnson-eg.dot");
129 fout <<
"graph A {\n" <<
"node[shape=\"circle\"]\n";
131 graph_traits < Graph >::edge_iterator ei, ei_end;
132 for (tie(ei, ei_end) =
edges(g); ei != ei_end; ++ei)
133 fout << source(*ei, g) <<
" -- " << target(*ei, g)
134 <<
"[label=" << get(edge_weight, g)[*ei] <<
"]\n";
void johnsons(unsigned const n, T **D, std::vector< Edge > const &es, std::valarray< T > const &eweights=std::valarray< T >())
find all pairs shortest paths, faster, uses dijkstra
void floyd_warshall(unsigned const n, T **D, std::vector< Edge > const &es, std::valarray< T > const &eweights=std::valarray< T >())
find all pairs shortest paths, n^3 dynamic programming approach