src/test/dijkstra_heap_test.cc
changeset 539 fb261e3a9a0f
parent 422 ede61a3d229b
child 542 69bde1d90c04
equal deleted inserted replaced
2:c081faf9a0c5 3:56f92604ca8b
    53   std::cout << "elapsed time: " << ts << std::endl;
    53   std::cout << "elapsed time: " << ts << std::endl;
    54   
    54   
    55   int error1=0;
    55   int error1=0;
    56   int error2=0;
    56   int error2=0;
    57 
    57 
    58   for(EdgeIt e=G.first(e); G.valid(e); G.next(e)) {
    58   EdgeIt e;
       
    59   for(G.first(e); G.valid(e); G.next(e)) {
    59     Node u=G.tail(e);
    60     Node u=G.tail(e);
    60     Node v=G.head(e);
    61     Node v=G.head(e);
    61     if ( dijkstra_test.dist(v) - dijkstra_test.dist(u) > cap[e] )
    62     if ( dijkstra_test.dist(v) - dijkstra_test.dist(u) > cap[e] )
    62       if ( dijkstra_test.reached(u) ) {
    63       if ( dijkstra_test.reached(u) ) {
    63 	std::cout<<"Error! dist(head)-dist(tail)- edge_length= " 
    64 	std::cout<<"Error! dist(head)-dist(tail)- edge_length= " 
    65 	  - cap[e]<<std::endl;
    66 	  - cap[e]<<std::endl;
    66 	++error1;
    67 	++error1;
    67       }
    68       }
    68   }
    69   }
    69 
    70 
    70   for(NodeIt v=G.first(v); G.valid(v); G.next(v)) {
    71   NodeIt v;
       
    72   for(G.first(v); G.valid(v); G.next(v)) {
    71     if ( dijkstra_test.reached(v) ) {
    73     if ( dijkstra_test.reached(v) ) {
    72       Edge e=dijkstra_test.pred(v);
    74       Edge e=dijkstra_test.pred(v);
    73       Node u=G.tail(e);
    75       Node u=G.tail(e);
    74       if ( dijkstra_test.dist(v) - dijkstra_test.dist(u) != cap[e] ) {
    76       if ( dijkstra_test.dist(v) - dijkstra_test.dist(u) != cap[e] ) {
    75 	std::cout<<"Error in a shortest path tree edge! Difference: " 
    77 	std::cout<<"Error in a shortest path tree edge! Difference: " 
    86 	    << " shortest path tree edge is erroneous."<<std::endl;
    88 	    << " shortest path tree edge is erroneous."<<std::endl;
    87 
    89 
    88 
    90 
    89 
    91 
    90   std::cout <<
    92   std::cout <<
    91     "\n  Testing dijkstra.h with Fibonacci heap implementation fib_heap.h,"
    93     "\n\n  Testing dijkstra.h with Fibonacci heap implementation fib_heap.h,"
    92 	    <<std::endl;
    94 	    <<std::endl;
    93   std::cout<<"  on a graph with " << 
    95   std::cout<<"  on a graph with " << 
    94     G.nodeNum() << " nodes and " << G.edgeNum() << " edges..."
    96     G.nodeNum() << " nodes and " << G.edgeNum() << " edges..."
    95 	   << std::endl<<std::endl;
    97 	   << std::endl<<std::endl;
    96   
    98   
   101   std::cout << "elapsed time: " << ts << std::endl;
   103   std::cout << "elapsed time: " << ts << std::endl;
   102   
   104   
   103   error1=0;
   105   error1=0;
   104   error2=0;
   106   error2=0;
   105 
   107 
   106   for(EdgeIt e=G.first(e); G.valid(e); G.next(e)) {
   108   for(G.first(e); G.valid(e); G.next(e)) {
   107     Node u=G.tail(e);
   109     Node u=G.tail(e);
   108     Node v=G.head(e);
   110     Node v=G.head(e);
   109     if ( dijkstra_test2.dist(v) - dijkstra_test2.dist(u) > cap[e] )
   111     if ( dijkstra_test2.dist(v) - dijkstra_test2.dist(u) > cap[e] )
   110       if ( dijkstra_test2.reached(u) ) {
   112       if ( dijkstra_test2.reached(u) ) {
   111 	std::cout<<"Error! dist(head)-dist(tail)- edge_length= " 
   113 	std::cout<<"Error! dist(head)-dist(tail)- edge_length= " 
   113 	  - cap[e]<<std::endl;
   115 	  - cap[e]<<std::endl;
   114 	++error1;
   116 	++error1;
   115       }
   117       }
   116   }
   118   }
   117 
   119 
   118   for(NodeIt v=G.first(v); G.valid(v); G.next(v)) {
   120   for(G.first(v); G.valid(v); G.next(v)) {
   119     if ( dijkstra_test2.reached(v) ) {
   121     if ( dijkstra_test2.reached(v) ) {
   120       Edge e=dijkstra_test2.pred(v);
   122       Edge e=dijkstra_test2.pred(v);
   121       Node u=G.tail(e);
   123       Node u=G.tail(e);
   122       if ( dijkstra_test2.dist(v) - dijkstra_test2.dist(u) != cap[e] ) {
   124       if ( dijkstra_test2.dist(v) - dijkstra_test2.dist(u) != cap[e] ) {
   123 	std::cout<<"Error in a shortest path tree edge! Difference: " 
   125 	std::cout<<"Error in a shortest path tree edge! Difference: "