Some more docs.
DirPath::Builder::setFist() added. (It is empty.)
1 //Tests dijsktra.h with two heap implementations:
2 //the default binary heap of bin_heap.h, and the
3 //Fibonacci heap of fib_heap.h.
5 //The input is a graph in standard dimacs format from the standard input (like
6 //in /hugo_loc/testfiles/dimacs). It runs dijkstra.h on this graph with both
7 //heaps, checking two postconditions:
9 //- if the edges e=uv of the shortest path tree reported by dijkstra.h have
10 //dist(v)-dist(u)=length(e)
12 // - if all edges e=uv with u reachable from the root have
13 //dist(v)-dist(u)>=length(e)
17 #include <smart_graph.h>
20 #include <time_measure.h>
26 int main(int, char **) {
28 typedef SmartGraph Graph;
30 typedef Graph::Edge Edge;
31 typedef Graph::Node Node;
32 typedef Graph::EdgeIt EdgeIt;
33 typedef Graph::NodeIt NodeIt;
34 typedef Graph::EdgeMap<int> LengthMap;
39 readDimacsMaxFlow(std::cin, G, s, t, cap);
43 "\n Testing dijkstra.h with binary heap implementation bin_heap.h,"
45 std::cout<<" on a graph with " <<
46 G.nodeNum() << " nodes and " << G.edgeNum() << " edges..."
47 << std::endl<<std::endl;
49 Dijkstra<Graph, LengthMap>
50 dijkstra_test(G, cap);
53 std::cout << "elapsed time: " << ts << std::endl;
58 for(EdgeIt e=G.first(e); G.valid(e); G.next(e)) {
61 if ( dijkstra_test.dist(v) - dijkstra_test.dist(u) > cap[e] )
62 if ( dijkstra_test.reached(u) ) {
63 std::cout<<"Error! dist(head)-dist(tail)- edge_length= "
64 <<dijkstra_test.dist(v) - dijkstra_test.dist(u)
70 for(NodeIt v=G.first(v); G.valid(v); G.next(v)) {
71 if ( dijkstra_test.reached(v) ) {
72 Edge e=dijkstra_test.pred(v);
74 if ( dijkstra_test.dist(v) - dijkstra_test.dist(u) != cap[e] ) {
75 std::cout<<"Error in a shortest path tree edge! Difference: "
76 <<std::abs(dijkstra_test.dist(v) - dijkstra_test.dist(u)
85 std::cout << error1 << " non-tree and " << error2
86 << " shortest path tree edge is erroneous."<<std::endl;
91 "\n Testing dijkstra.h with Fibonacci heap implementation fib_heap.h,"
93 std::cout<<" on a graph with " <<
94 G.nodeNum() << " nodes and " << G.edgeNum() << " edges..."
95 << std::endl<<std::endl;
97 Dijkstra<Graph, LengthMap, FibHeap>
98 dijkstra_test2(G, cap);
100 dijkstra_test2.run(s);
101 std::cout << "elapsed time: " << ts << std::endl;
106 for(EdgeIt e=G.first(e); G.valid(e); G.next(e)) {
109 if ( dijkstra_test2.dist(v) - dijkstra_test2.dist(u) > cap[e] )
110 if ( dijkstra_test2.reached(u) ) {
111 std::cout<<"Error! dist(head)-dist(tail)- edge_length= "
112 <<dijkstra_test2.dist(v) - dijkstra_test2.dist(u)
118 for(NodeIt v=G.first(v); G.valid(v); G.next(v)) {
119 if ( dijkstra_test2.reached(v) ) {
120 Edge e=dijkstra_test2.pred(v);
122 if ( dijkstra_test2.dist(v) - dijkstra_test2.dist(u) != cap[e] ) {
123 std::cout<<"Error in a shortest path tree edge! Difference: "
124 <<std::abs(dijkstra_test2.dist(v) - dijkstra_test2.dist(u)
125 - cap[e])<<std::endl;
132 std::cout << error1 << " non-tree and " << error2
133 << " shortest path tree edge is erroneous."<<std::endl;