To be on the safe side...
     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
 
     7 //both 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>
 
    23 #include <for_each_macros.h>
 
    27 int main(int, char **) {
 
    29   typedef SmartGraph Graph;
 
    31   typedef Graph::Edge Edge;
 
    32   typedef Graph::Node Node;
 
    33   typedef Graph::EdgeIt EdgeIt;
 
    34   typedef Graph::NodeIt NodeIt;
 
    35   typedef Graph::EdgeMap<int> LengthMap;
 
    40   readDimacsMaxFlow(std::cin, G, s, t, cap);
 
    44     "\n  Testing dijkstra.h with binary heap implementation bin_heap.h,"
 
    46   std::cout<<"  on a graph with " << 
 
    47     G.nodeNum() << " nodes and " << G.edgeNum() << " edges..."
 
    48 	   << std::endl<<std::endl;
 
    50   Dijkstra<Graph, LengthMap> 
 
    51     dijkstra_test(G, cap);
 
    54   std::cout << "elapsed time: " << ts << std::endl;
 
    59   FOR_EACH_LOC ( EdgeIt, e, G) {
 
    62     if ( dijkstra_test.dist(v) - dijkstra_test.dist(u) > cap[e] )
 
    63       if ( dijkstra_test.reached(u) ) {
 
    64 	std::cout<<"Error! dist(head)-dist(tail)- edge_length= " 
 
    65 		 <<dijkstra_test.dist(v) - dijkstra_test.dist(u) 
 
    71   FOR_EACH_LOC ( NodeIt, v, G) {
 
    72     if ( dijkstra_test.reached(v) ) {
 
    73       Edge e=dijkstra_test.pred(v);
 
    75       if ( dijkstra_test.dist(v) - dijkstra_test.dist(u) != cap[e] ) {
 
    76 	std::cout<<"Error in a shortest path tree edge! Difference: " 
 
    77 		 <<std::abs(dijkstra_test.dist(v) - dijkstra_test.dist(u) 
 
    86   std::cout << error1 << " non-tree and " << error2 
 
    87 	    << " shortest path tree edge is erroneous."<<std::endl;
 
    92     "\n  Testing dijkstra.h with Fibonacci heap implementation fib_heap.h,"
 
    94   std::cout<<"  on a graph with " << 
 
    95     G.nodeNum() << " nodes and " << G.edgeNum() << " edges..."
 
    96 	   << std::endl<<std::endl;
 
    98   Dijkstra<Graph, LengthMap, FibHeap> 
 
    99     dijkstra_test2(G, cap);
 
   101   dijkstra_test2.run(s);
 
   102   std::cout << "elapsed time: " << ts << std::endl;
 
   107   FOR_EACH_LOC ( EdgeIt, e, G) {
 
   110     if ( dijkstra_test2.dist(v) - dijkstra_test2.dist(u) > cap[e] )
 
   111       if ( dijkstra_test2.reached(u) ) {
 
   112 	std::cout<<"Error! dist(head)-dist(tail)- edge_length= " 
 
   113 		 <<dijkstra_test2.dist(v) - dijkstra_test2.dist(u) 
 
   119   FOR_EACH_LOC ( NodeIt, v, G) {
 
   120     if ( dijkstra_test2.reached(v) ) {
 
   121       Edge e=dijkstra_test2.pred(v);
 
   123       if ( dijkstra_test2.dist(v) - dijkstra_test2.dist(u) != cap[e] ) {
 
   124 	std::cout<<"Error in a shortest path tree edge! Difference: " 
 
   125 		 <<std::abs(dijkstra_test2.dist(v) - dijkstra_test2.dist(u) 
 
   126 			    - cap[e])<<std::endl;
 
   133   std::cout << error1 << " non-tree and " << error2 
 
   134 	    << " shortest path tree edge is erroneous."<<std::endl;