Commit 53d3c595 authored by Nathan Rébiscoul's avatar Nathan Rébiscoul
Browse files

Add algo dijkstra-ring-NR which is working. And start dfs-NR.

parent ad64d0fc
Pipeline #24662 passed with stage
in 8 minutes and 33 seconds
# Time-stamp: <modified the 23/05/2019 (at 16:18) by Erwan Jahier>
test: p.cmxs root.cmxs ring.lut
$(sasa) -l 20 -sd ring.dot
cmxs: p.cmxs root.cmxs p.cma root.cma
sim2chrogtk: ring.rif
sim2chrogtk -ecran -in $< > /dev/null
gnuplot: ring.rif
gnuplot-rif $<
rdbg: p.cma root.cma ring.lut
rdbg -o ring.rif \
-env "$(sasa) g.dot -cd"
-include ../Makefile.inc
#sasa=sasa -l 10
(* Some useful short-cuts for rdbg interactive sessions *)
let _ = time_travel true;;
let e = ref (RdbgStdLib.run());;
let s () = e:=step !e;;
let si i = e:=stepi !e i;;
let n () = e:=next !e ;;
let ni i = e:= nexti !e i;;
let g i = e:= goto !e i;;
let b () = e:= back !e ;;
let bi i = e:= backi !e i;;
let r () = !e.Event.reset(); e:= RdbgStdLib.run();;
let c () = e:= continue !e;;
let bt () = print_src !e;;
let finish () = loopforever !e;;
(**********************************************************************)
#require "ocamlgraph";;
#mod_use "../../lib/algo/algo.ml";;
#mod_use "../../lib/sasacore/topology.ml";;
#use "../rdbg-utils/dot.ml";;
let p = Topology.read dotfile;;
let d () = dot p dotfile !e;;
let ne () = neato p dotfile !e;;
let tw () = twopi p dotfile !e;;
let ci () = circo p dotfile !e;;
let fd () = fdp p dotfile !e;;
let sf () = sfdp p dotfile !e;;
let pa () = patchwork p dotfile !e;;
let os () = osage p dotfile !e;;
(* Convergence is reached when data does not change *)
let rec go () =
let data = !e.data in
s(); if data = !e.data then ci () else go () ;;
let sd () = s();ci();;
let nd () = n();ci();;
let bd () = b();ci();;
(**********************************************************************)
let get_removable pl =
let pl = List.filter
(fun p ->
(List.exists (fun (_,_,acti) -> acti) p.actions) ||
(List.for_all (fun (_,enab,_) -> (not enab)) p.actions)
)
pl
in
List.map (fun p -> p.name) pl
let verbose = ref false
let last_round = ref 0
let round_nodes = ref [] (* nodes we look the activation at *)
let (round : Event.t -> bool) =
fun e ->
let (pl : process list) = get_processes e in
let rm_me = get_removable pl in
if !verbose then (
Printf.printf "Current process: %s\n" (String.concat "," !round_nodes);
Printf.printf "Rm_Me process: %s\n" (String.concat "," rm_me);
flush stdout;
);
round_nodes := List.filter (fun pid -> not (List.mem pid rm_me)) !round_nodes;
let res = !round_nodes = [] ||
(* when round is called twice, it should have the same
result *)
!last_round = e.nb
in
if !round_nodes = [] then (
last_round := e.nb;
round_nodes := (
let p_with_enable_action =
List.filter
(fun p -> List.exists
(fun (_,enab,acti) -> enab && not(acti)) p.actions)
pl
in
let pidl = List.map (fun p -> p.name) p_with_enable_action in
let pidl = List.rev pidl in
if !verbose then (
Printf.printf "The processes to check : %s\n" (String.concat "," pidl);
flush stdout
);
pidl
)
);
res
(* go to next and previous rounds *)
let next_round e = next_cond e round;;
let nr () = e:=next_round !e; circo p dotfile !e;;
let pr () = e:=goto_last_ckpt !e.nb; circo p dotfile !e;;
(* checkpoint at rounds! *)
let _ = check_ref := round;;
let _ = ci (); Sys.command (Printf.sprintf "zathura sasa-%s.pdf&" dotfile)
let _ = print_string "
--> type 'man' for online help
"
;;
(* Time-stamp: <modified the 27/05/2019 (at 16:52) by Erwan Jahier> *)
(* a dumb algo *)
open Algo
let vars = [("d",It);("par",Nt)] ;;
let d = 3+1 ;;
let (init_vars: neighbor list -> local_env) =
fun nl ->
function
| "d" -> I (Random.int d)
| "par" -> N (Random.int (List.length nl))
| _ -> assert false
;;
let (dist:neighbor list -> int) =
fun nl ->
let d_liste = (List.map (fun n-> let I x = (n.lenv "d") in x) nl) in
(List.fold_left min (d-1) d_liste) + 1
;;
let (p_parent:neighbor list -> local_env -> neighbor) =
fun nl e ->
let N x = (e "par") in
List.nth nl x
;;
let (distOK:neighbor list -> local_env -> bool) =
fun nl e->
let d_liste = List.map (fun n-> let I x = (n.lenv "d") in x) nl in
let I d = e "d" in
let h::t = d_liste in
(d-1) = (List.fold_left min h t)
;;
let (enable_f:neighbor list -> local_env -> action list) =
fun nl e ->
let I x = e "d" in
let I y = (p_parent nl e).lenv "d" in
(if ((dist nl) <> x) then ["CD"] else (if (distOK nl e) && y<>(x-1) then ["CP"] else []))
;;
let (step_f : neighbor list -> local_env -> action -> local_env) =
fun nl e ->
function
| "CD" -> (function "d" -> I (dist nl) | a -> e a)
| "CP" -> (function "par" ->
let I d = e "d" in
let p = List.map (fun n -> let I y = (n.lenv "d") in y) nl in
N (List.fold_right
(fun n i -> if (n=d-1) then 0 else i + 1 ) p 0)
| a -> e a)
| _ -> e
;;
let () =
let algo_id = "p" in
Algo.reg_actions algo_id ["CD";"CP"];
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;
()
graph ring7 {
root [algo="root.ml"]
p1 [algo="p.ml" ]
p2 [algo="p.ml"]
p3 [algo="p.ml"]
p4 [algo="p.ml"]
p5 [algo="p.ml"]
p6 [algo="p.ml"]
root -- p1 -- p2 -- p3 -- p4 -- p5 -- p6 -- root
}
(* Time-stamp: <modified the 27/05/2019 (at 16:52) by Erwan Jahier> *)
(* a dumb algo *)
open Algo
let vars = ["d",It] ;;
let d = 3+1 ;;
let (init_vars: neighbor list -> local_env) =
fun _nl ->
function _ -> I (Random.int d)
;;
let (enable_f:neighbor list ->local_env -> action list) =
fun _ e ->
let I x = e "d" in
if x <> 0 then ["misea0"]
else []
;;
let (step_f : neighbor list -> local_env -> action -> local_env) =
fun nl e ->
function
| "misea0" -> (function "d" -> I 0 | _ -> assert false)
| _ -> e
;;
let () =
let algo_id = "root" in
Algo.reg_actions algo_id ["misea0"];
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;
()
;;
......@@ -15,7 +15,7 @@ gnuplot: ring.rif
rdbg: p.cma root.cma ring.lut
rdbg -o ring.rif \
-env "$(sasa) g.dot -cd"
-env "$(sasa) ring.dot -cd"
-include ../Makefile.inc
#sasa=sasa -l 10
......@@ -4,61 +4,35 @@
open Algo
let vars = [("d",It);("par",Nt)] ;;
let d = 3+1 ;;
let vars = [("t",It)] ;;
let k = 3+1 ;;
let (init_vars: neighbor list -> local_env) =
fun nl ->
function
| "d" -> I (Random.int d)
| "par" -> N (Random.int (List.length nl))
| "t" -> I (Random.int k)
| _ -> assert false
;;
let (dist:neighbor list -> int) =
fun nl ->
let d_liste = (List.map (fun n-> let I x = (n.lenv "d") in x) nl) in
(List.fold_left min (d-1) d_liste) + 1
;;
let (p_parent:neighbor list -> local_env -> neighbor) =
let (tokenpx:neighbor list -> local_env -> bool) =
fun nl e ->
let N x = (e "par") in
List.nth nl x
;;
let (distOK:neighbor list -> local_env -> bool) =
fun nl e->
let d_liste = List.map (fun n-> let I x = (n.lenv "d") in x) nl in
let I d = e "d" in
let h::t = d_liste in
(d-1) = (List.fold_left min h t)
(List.hd nl).lenv "t" <> e "t"
;;
let (enable_f:neighbor list -> local_env -> action list) =
let (enable_f:neighbor list ->local_env -> action list) =
fun nl e ->
let I x = e "d" in
let I y = (p_parent nl e).lenv "d" in
(if ((dist nl) <> x) then ["CD"] else (if (distOK nl e) && y<>(x-1) then ["CP"] else []))
if tokenpx nl e then ["change"]
else []
;;
let (step_f : neighbor list -> local_env -> action -> local_env) =
fun nl e ->
function
| "CD" -> (function "d" -> I (dist nl) | a -> e a)
| "CP" -> (function "par" ->
let I d = e "d" in
let p = List.map (fun n -> let I y = (n.lenv "d") in y) nl in
N (List.fold_right
(fun n i -> if (n=d-1) then 0 else i + 1 ) p 0)
| a -> e a)
| "change" -> (function "t" -> (List.hd nl).lenv "t" | _ -> assert false )
| _ -> e
;;
;;
let () =
let algo_id = "p" in
Algo.reg_actions algo_id ["CD";"CP"];
Algo.reg_actions algo_id ["change"];
Algo.reg_vars algo_id vars;
Algo.reg_init_vars algo_id init_vars;
Algo.reg_enable algo_id enable_f;
......
......@@ -7,39 +7,35 @@ open Algo
let vars = ["t",It] ;;
let k = 3+1 ;;
let (init_vars: neighbor list -> local_env) =
fun nl ->
function _nl
| "t" -> I (Random.int d)
| _ -> assert false
fun _nl ->
function
|"t" -> I (Random.int k)
;;
let (token:neighbor list -> local_env -> bool) =
fun nl e ->
let pere = List.hd nl in
let I v = "t" e in
let I vpred = "par" pere in
if vpred = v then ["change"] else []
(List.hd nl).lenv "t" = e "t"
;;
let (enable_f:neighbor list ->local_env -> action list) =
fun _ e ->
let I x = e "t" in
if x <> 0 then ["misea0"]
fun nl e ->
if token nl e then ["change"]
else []
;;
let (step_f : neighbor list -> local_env -> action -> local_env) =
fun nl e ->
function
| "misea0" -> (function "t" -> I 0 | _ -> assert false)
| "change" -> (function "t" -> let I v = (e "t") in I ((v + 1) mod k) | _ -> assert false )
| _ -> e
;;
let () =
let algo_id = "root" in
Algo.reg_actions algo_id ["misea0"];
Algo.reg_actions algo_id ["change"];
Algo.reg_vars algo_id vars;
Algo.reg_init_vars algo_id init_vars;
Algo.reg_enable algo_id enable_f;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment