home *** CD-ROM | disk | FTP | other *** search
- #include <LEDA/graph.h>
- #include <LEDA/graph_alg.h>
-
- declare2(GRAPH,int,int);
-
- main()
- {
-
- GRAPH(int,int) G;
- node s,v,w;
- edge e;
-
- int n = read_int("# nodes = ");
- int m = read_int("# edges = ");
-
-
- edge_array(int) cost(G,m,0);
- node_array(int) dist(G,n,0);
- node_array(int) dist2(G,n,0);
-
- edge_array(real) cost1(G,m,0);
- node_array(real) dist1(G,n,0);
- node_array(real) dist3(G,n,0);
-
- node_array(edge) pred(G,n,nil);
-
- random_graph(G,n,m);
-
- int a = read_int("a = ");
- int b = read_int("b = ");
-
- init_random();
- forall_edges(e,G) cost1[e] = cost[e] = G[e] = random(a,b);
-
-
-
- s = G.first_node();
-
- float T = used_time();
-
- cout << "DIJKSTRA (int) ";
- cout.flush();
- DIJKSTRA(G,s,cost,dist,pred);
- cout << form("%6.2f sec \n",used_time(T));
-
- cout << "DIJKSTRA (real) ";
- cout.flush();
- DIJKSTRA(G,s,cost1,dist1,pred);
- cout << form("%6.2f sec \n",used_time(T));
-
- cout << "BELLMAN_FORD (int) ";
- cout.flush();
- BELLMAN_FORD(G,s,cost,dist2,pred);
- cout << form("%6.2f sec \n",used_time(T));
-
-
- cout << "BELLMAN_FORD (real) ";
- cout.flush();
- BELLMAN_FORD(G,s,cost1,dist3,pred);
- cout << form("%6.2f sec \n",used_time(T));
-
- if (Yes("Ausgabe ? "))
- { forall_nodes(v,G)
- { G.print_node(v);
- cout << form(" %6d %6.2f %6d %6.2f\n",dist[v],~dist1[v],dist2[v],~dist3[v]);
- }
- newline;
- }
-
-
- if (Yes("all pairs shortest paths (int) ? "))
- {
- node_matrix(int) Mi(G);
-
- used_time(T);
- cout << "ALL PAIRS SHORTEST PATHS (int) ";
- cout.flush();
- ALL_PAIRS_SHORTEST_PATHS(G,cost,Mi);
- cout << form("%.2f sec\n",used_time(T));
-
- if (Yes("Ausgabe ? "))
- forall_nodes(v,G)
- { forall_nodes(w,G) cout << form("%6d ",Mi(v,w));
- newline;
- }
- newline;
- }
-
-
- if (Yes("all pairs shortest paths (real) ? "))
- {
- node_matrix(real) Mr(G);
-
- used_time(T);
- cout << "ALL PAIRS SHORTEST PATHS (real) ";
- cout.flush();
- ALL_PAIRS_SHORTEST_PATHS(G,cost1,Mr);
- cout << form("%.2f sec\n",used_time(T));
-
- if (Yes("Ausgabe ? "))
- forall_nodes(v,G)
- { forall_nodes(w,G) cout << form("%6.2f ",~Mr(v,w));
- newline;
- }
- newline;
-
- }
-
- }
-