commit 02328e94c4cc3b3b1a7d4c57f2170257795526c3 Author: josch Date: Wed Jul 4 14:23:50 2012 +0200 initial commit diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..742813b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,12 @@ +[submodule "abate"] + path = abate + url = git://github.com/josch/cycles_johnson_abate.git +[submodule "hawick"] + path = hawick + url = git://github.com/josch/cycles_hawick_james.git +[submodule "meyer"] + path = meyer + url = git://github.com/josch/cycles_johnson_meyer.git +[submodule "tarjan"] + path = tarjan + url = git://github.com/josch/cycles_tarjan.git diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..02f5c5f --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +CFLAGS=-Xs abate,hawick,meyer,tarjan + +all: + ocamlbuild ${CFLAGS} -classic-display -use-ocamlfind rand_graph.native + +clean: + ocamlbuild ${CFLAGS} -clean + rm -f *.dot diff --git a/README.md b/README.md new file mode 100644 index 0000000..e465d70 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +Run cycle enumerating code on sample input and compare results +-------------------------------------------------------------- + +An ocaml script generates random directed graphs with loops. + +Those loops are fed to a number of different cycle enumeration algorithms. + +The outputs are compared with each other to ensure correct execution. + +Setup +----- + + git submodule update --init + +Usage +----- + + ./test.sh 11 + +The argument to the shell script is an integer denoting the maximum number of +vertices for which graphs will be generated. diff --git a/_tags b/_tags new file mode 100644 index 0000000..add6ce7 --- /dev/null +++ b/_tags @@ -0,0 +1,2 @@ +<*.ml{i,}>: debug, pp(camlp4o Camlp4MacroParser.cmo) +: package(ocamlgraph), package(extlib) diff --git a/rand_graph.ml b/rand_graph.ml new file mode 100644 index 0000000..f9b98d9 --- /dev/null +++ b/rand_graph.ml @@ -0,0 +1,22 @@ +open Graph +module G = Pack.Digraph +module Dfs = Graph.Traverse.Dfs(G) + +if Array.length Sys.argv != 2 then begin + Printf.printf "usage: %s max_num_vertices\n" Sys.argv.(0); + exit 1; +end; + +let max_v = int_of_string Sys.argv.(1) in + +for v = 1 to max_v do + let e = ref 1 in + try + while true do + let g = G.Rand.graph ~v ~e:!e () in + if Dfs.has_cycle g then + G.dot_output g (Printf.sprintf "graph-%d-%d.dot" v !e); + incr e; + done; + with _ -> (); +done; diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..5cfad73 --- /dev/null +++ b/test.sh @@ -0,0 +1,46 @@ +#!/bin/sh -e + +echo compiling ./hawick/circuits_hawick... +make -C ./hawick >/dev/null +echo compiling ./meyer/de/normalisiert/utils/graphs/TestCycles.class +make -C ./meyer >/dev/null +echo compiling ./abate/cycles_iter.native and ./abate/cycles_functional.native +make -C ./abate >/dev/null +echo compiling ./rand_graph.native... +make > /dev/null +echo generating random graphs... +rm -f *.dot +./rand_graph.native $1 +echo testing graphs... +counter=0 +for f in *.dot; do + num_vertices=$(sed -n -e '/^ [0-9]\+;$/p' $f | wc -l) + adj_list=$(sed -n -e 's/^ \([0-9]\) -> \([0-9]\);$/\1,\2/p' $f) + + result_hawick=$(./hawick/circuits_hawick $num_vertices $(echo $adj_list)) + result_meyer=$(java -classpath ./meyer de.normalisiert.utils.graphs.TestCycles $num_vertices $(echo $adj_list)) + result_tarjan=$(python ./tarjan/cycles.py $num_vertices $(echo $adj_list)) + result_abate_iter=$(./abate/cycles_iter.native $num_vertices $(echo $adj_list)) + result_abate_func=$(./abate/cycles_functional.native $num_vertices $(echo $adj_list)) + + if [ "$result_hawick" != "$result_meyer" ]; then + echo error: hawick differs from meyer + exit 1 + fi + if [ "$result_hawick" != "$result_tarjan" ]; then + echo error: hawick differs from tarjan + exit 1 + fi + if [ "$result_hawick" != "$result_abate_iter" ]; then + echo error: hawick differs from abate_iter + exit 1 + fi + if [ "$result_hawick" != "$result_abate_func" ]; then + echo error: hawick differs from abate_func + exit 1 + fi + echo $f okay, $(echo "$result_hawick" | wc -l) cycles + counter=$((counter+1)) +done +echo successfully tested $counter graphs +