diff --git a/test/Makefile b/test/Makefile index 52f9d7caa385024e4645fcfcb09c79d1d55f384d..3036707f6a008ec1938fa566b003427fd0135995 100644 --- a/test/Makefile +++ b/test/Makefile @@ -2,7 +2,9 @@ test: cd dijkstra-ring/ && make cd unison/ && make + cd coloring/ && make clean: cd dijkstra-ring/ && make clean cd unison/ && make clean + cd coloring/ && make clean diff --git a/test/coloring/Makefile b/test/coloring/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..a0509e5dd8af886e8ce79109be4ba55030d933ce --- /dev/null +++ b/test/coloring/Makefile @@ -0,0 +1,8 @@ +# Time-stamp: <modified the 07/03/2019 (at 15:44) by Erwan> + + +test: p.cmxs + $(sasa) -l 200 ring.dot + +-include ../Makefile.inc + diff --git a/test/coloring/p.ml b/test/coloring/p.ml new file mode 100644 index 0000000000000000000000000000000000000000..28c69540b8a1538902c038eb503db95f21d4fb31 --- /dev/null +++ b/test/coloring/p.ml @@ -0,0 +1,42 @@ +(* Time-stamp: <modified the 07/03/2019 (at 16:25) by Erwan> *) + +(* This is algo 3.1 in the book *) + +open Algo + +let vars = ["c",It] +let k=3 + +let init_vars = function _ -> I (Random.int k) + + +let (used : neighbor list -> Algo.value list) = fun nl -> + let res = List.map (fun n -> n.lenv "c") nl in + res + +let (free : neighbor list -> Algo.value list) = fun nl -> + let used_list = List.sort_uniq compare (used nl) in + let rec aux free used i = + if i > k then free else + (match used with + | x::tail -> if x = I i then aux free tail (i+1) else aux ((I i)::free) used (i+1) + | [] -> aux ((I i)::free) used (i+1) + ) + in + let res = aux [] used_list 0 in + List.rev res + +let enable_f nl e = if List.mem (e "c") (used nl) then ["conflict"] else [] + +let step_f nl e = + function | _ -> (function "c" -> List.hd (free nl) | _ -> assert false) + + +let () = + let algo_id = "p" in + Algo.reg_vars algo_id vars; + Algo.reg_init_vars algo_id init_vars; + Algo.reg_enable algo_id enable_f; + Algo.reg_step algo_id step_f; + () + diff --git a/test/coloring/ring.dot b/test/coloring/ring.dot new file mode 100644 index 0000000000000000000000000000000000000000..4d342bedd98a240aa6abfc200bce4adcc7f72251 --- /dev/null +++ b/test/coloring/ring.dot @@ -0,0 +1,13 @@ +graph ring7 { + + p1 [algo="p.cmxs"] + p2 [algo="p.cmxs" ] + p3 [algo="p.cmxs"] + p4 [algo="p.cmxs"] + p5 [algo="p.cmxs"] + p6 [algo="p.cmxs"] + p7 [algo="p.cmxs"] + + p1 -- p2 -- p3 -- p4 -- p5 -- p6 -- p7 -- p1 + +}