[Lemon-commits] [lemon_svn] jacint: r514 - hugo/trunk/src/test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:39:53 CET 2006
Author: jacint
Date: Fri Apr 23 20:48:56 2004
New Revision: 514
Added:
hugo/trunk/src/test/dijkstra_heap_test.cc
hugo/trunk/src/test/makefile
Log:
Testfile for dijkstra.h, bin_heap.h and fib_heap.h
Added: hugo/trunk/src/test/dijkstra_heap_test.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/src/test/dijkstra_heap_test.cc Fri Apr 23 20:48:56 2004
@@ -0,0 +1,137 @@
+//Tests dijsktra.h with two heap implementations:
+//the default binary heap of bin_heap.h, and the
+//Fibonacci heap of fib_heap.h.
+
+//The input is a graph in standard dimacs format from the standard input (like
+//in /hugo_loc/testfiles/dimacs). It runs dijkstra.h on this graph with
+//both heaps, checking two postconditions:
+
+//- if the edges e=uv of the shortest path tree reported by dijkstra.h have
+//dist(v)-dist(u)=length(e)
+
+// - if all edges e=uv with u reachable from the root have
+//dist(v)-dist(u)>=length(e)
+#include <iostream>
+#include <math.h>
+
+#include <smart_graph.h>
+#include <dimacs.h>
+#include <dijkstra.h>
+#include <time_measure.h>
+#include <bin_heap.h>
+#include <for_each_macros.h>
+
+using namespace hugo;
+
+int main(int, char **) {
+
+ typedef SmartGraph Graph;
+
+ typedef Graph::Edge Edge;
+ typedef Graph::Node Node;
+ typedef Graph::EdgeIt EdgeIt;
+ typedef Graph::NodeIt NodeIt;
+ typedef Graph::EdgeMap<int> LengthMap;
+
+ Graph G;
+ Node s, t;
+ LengthMap cap(G);
+ readDimacsMaxFlow(std::cin, G, s, t, cap);
+ Timer ts;
+
+ std::cout <<
+ "\n Testing dijkstra.h with binary heap implementation bin_heap.h,"
+ <<std::endl;
+ std::cout<<" on a graph with " <<
+ G.nodeNum() << " nodes and " << G.edgeNum() << " edges..."
+ << std::endl<<std::endl;
+
+ Dijkstra<Graph, LengthMap>
+ dijkstra_test(G, cap);
+ ts.reset();
+ dijkstra_test.run(s);
+ std::cout << "elapsed time: " << ts << std::endl;
+
+ int error1=0;
+ int error2=0;
+
+ FOR_EACH_LOC ( EdgeIt, e, G) {
+ Node u=G.tail(e);
+ Node v=G.head(e);
+ if ( dijkstra_test.dist(v) - dijkstra_test.dist(u) > cap[e] )
+ if ( dijkstra_test.reached(u) ) {
+ std::cout<<"Error! dist(head)-dist(tail)- edge_length= "
+ <<dijkstra_test.dist(v) - dijkstra_test.dist(u)
+ - cap[e]<<std::endl;
+ ++error1;
+ }
+ }
+
+ FOR_EACH_LOC ( NodeIt, v, G) {
+ if ( dijkstra_test.reached(v) ) {
+ Edge e=dijkstra_test.pred(v);
+ Node u=G.tail(e);
+ if ( dijkstra_test.dist(v) - dijkstra_test.dist(u) != cap[e] ) {
+ std::cout<<"Error in a shortest path tree edge! Difference: "
+ <<std::abs(dijkstra_test.dist(v) - dijkstra_test.dist(u)
+ - cap[e])<<std::endl;
+ ++error2;
+ }
+ }
+ }
+
+
+
+ std::cout << error1 << " non-tree and " << error2
+ << " shortest path tree edge is erroneous."<<std::endl;
+
+
+
+ std::cout <<
+ "\n Testing dijkstra.h with Fibonacci heap implementation fib_heap.h,"
+ <<std::endl;
+ std::cout<<" on a graph with " <<
+ G.nodeNum() << " nodes and " << G.edgeNum() << " edges..."
+ << std::endl<<std::endl;
+
+ Dijkstra<Graph, LengthMap, FibHeap>
+ dijkstra_test2(G, cap);
+ ts.reset();
+ dijkstra_test2.run(s);
+ std::cout << "elapsed time: " << ts << std::endl;
+
+ error1=0;
+ error2=0;
+
+ FOR_EACH_LOC ( EdgeIt, e, G) {
+ Node u=G.tail(e);
+ Node v=G.head(e);
+ if ( dijkstra_test2.dist(v) - dijkstra_test2.dist(u) > cap[e] )
+ if ( dijkstra_test2.reached(u) ) {
+ std::cout<<"Error! dist(head)-dist(tail)- edge_length= "
+ <<dijkstra_test2.dist(v) - dijkstra_test2.dist(u)
+ - cap[e]<<std::endl;
+ ++error1;
+ }
+ }
+
+ FOR_EACH_LOC ( NodeIt, v, G) {
+ if ( dijkstra_test2.reached(v) ) {
+ Edge e=dijkstra_test2.pred(v);
+ Node u=G.tail(e);
+ if ( dijkstra_test2.dist(v) - dijkstra_test2.dist(u) != cap[e] ) {
+ std::cout<<"Error in a shortest path tree edge! Difference: "
+ <<std::abs(dijkstra_test2.dist(v) - dijkstra_test2.dist(u)
+ - cap[e])<<std::endl;
+ ++error2;
+ }
+ }
+ }
+
+
+ std::cout << error1 << " non-tree and " << error2
+ << " shortest path tree edge is erroneous."<<std::endl;
+
+
+ return 0;
+}
Added: hugo/trunk/src/test/makefile
==============================================================================
--- (empty file)
+++ hugo/trunk/src/test/makefile Fri Apr 23 20:48:56 2004
@@ -0,0 +1,22 @@
+CXX3 := $(shell type -p g++-3.3 || type -p g++-3.2 || type -p g++-3.0 || type -p g++-3 || echo g++)
+CXX2 = g++-2.95
+CXX=$(CXX3)
+CC=$(CXX)
+INCLUDEDIRS ?= -I../include -I.. -I../work/{marci,jacint,alpar,klao,akos,athos}
+CXXFLAGS = -W -Wall -ansi -pedantic -O3 $(INCLUDEDIRS)
+LEDAROOT ?= /ledasrc/LEDA-4.1
+
+BINARIES = dijkstra_heap_test
+
+all: $(BINARIES)
+
+.depend dep depend:
+ -$(CXX) $(INCLUDEDIRS) -M $(BINARIES:=.cc) > .depend #2>/dev/null
+
+makefile: .depend
+sinclude .depend
+
+clean:
+ $(RM) *.o $(BINARIES) .depend
+
+.PHONY: all clean dep depend
More information about the Lemon-commits
mailing list