Skip to content
Snippets Groups Projects
Commit dc0fc159 authored by erwan's avatar erwan
Browse files

New: add a --ignore-first-inputs option.

This is necessary to be able to use sasa with luciole.  Indeed, in
rdbg/lurette, luciole always plays first. Hence if we want sasa to
play after luciole, we can use the option.
parent 40e253bf
No related branches found
No related tags found
No related merge requests found
Pipeline #20849 passed
(* Time-stamp: <modified the 13/03/2019 (at 10:10) by Erwan Jahier> *)
(* Time-stamp: <modified the 13/03/2019 (at 17:44) by Erwan Jahier> *)
type t =
| Synchronous (* select all actions *)
......@@ -29,21 +29,6 @@ let (synchrone: 'a list list -> 'a list) = fun all ->
al
(* xxx use RifIO.read instead ! *)
let read_bool rif_mode p =
let x = input_char stdin in
if not rif_mode then (
Printf.printf "Enter a bool [1,t,T|0,f,F] for process %s\n" p.Process.pid;
flush stdout
);
let rec aux x =
match x with
| '0' | 'f' | 'F' -> false
| '1' | 't' | 'T' -> true
| 'q' -> Printf.eprintf "bye\n"; flush stdout; exit 0
| _ -> aux (input_char stdin)
in
aux x
type pna = Process.t * Topology.neighbor list * Algo.action
(* From a list of enabled actions (pna) returns:
......@@ -68,23 +53,23 @@ let rec map3 f l1 l2 l3 =
let (custom: bool -> pna list list -> Process.t list -> bool list list
-> string * pna list) =
fun rif_mode all pl enab_ll ->
let f p al enab_l =
fun verbose_mode pnall pl enab_ll ->
let f p pnal enab_l =
let actions = p.Process.actions in
let trigger_l = List.map (fun _a -> read_bool rif_mode p) actions in
let trigger_l = List.map (fun a -> RifRead.bool verbose_mode p a) actions in
let acti_l_al =
map3
(fun trig enab a ->
let acti = trig && enab in
acti, if acti then
let pna = List.find (fun (_,_,a') -> a=a') al in
let pna = List.find (fun (_,_,a') -> a=a') pnal in
[pna]
else []
) trigger_l enab_l actions
in
acti_l_al
in
let acti_l_all = map3 f pl all enab_ll in
let acti_l_all = map3 f pl pnall enab_ll in
let acti_l_al = List.flatten acti_l_all in
let acti_l,al = List.split acti_l_al in
let acti = String.concat " " (List.map (fun b -> if b then "t" else "f") acti_l) in
......@@ -96,13 +81,13 @@ let (remove_empty_list: 'a list list -> 'a list list) =
let (f: bool -> t -> Process.t list -> pna list list -> bool list list ->
string * pna list) =
fun rif_mode demon pl all enab ->
fun verbose_mode demon pl all enab ->
match demon with
| Synchronous -> "", synchrone (remove_empty_list all)
| Central -> "", random1 (remove_empty_list all)
| LocallyCentral -> assert false
| Distributed -> "", random (remove_empty_list all)
| Custom -> custom rif_mode all pl enab
| Custom -> custom verbose_mode all pl enab
(* Time-stamp: <modified the 13/03/2019 (at 17:54) by Erwan Jahier> *)
(* xxx use RifIO.read instead ! *)
let bool verbose_mode p a =
if verbose_mode then (
Printf.eprintf "Enter a bool [1,t,T|0,f,F] for process %s\n" p.Process.pid;
flush stderr
);
let x = input_char stdin in
let rec aux x =
match x with
| '0' | 'f' | 'F' -> false
| '1' | 't' | 'T' -> true
| 'q' -> Printf.eprintf "bye\n"; flush stderr; exit 0
| '#' -> skip_comment ()
| x ->
if verbose_mode then (Printf.eprintf "'%c'" x; flush stderr);
aux (input_char stdin)
and skip_comment () =
match input_char stdin with
| '\n' -> aux (input_char stdin)
| _ -> skip_comment ()
in
let res = aux x in
if verbose_mode then (
flush stderr;
Printf.eprintf "%s_%s<-%s\n" p.Process.pid a (if res then "t" else "f");
flush stderr
);
res
(* Time-stamp: <modified the 13/03/2019 (at 17:45) by Erwan Jahier> *)
(** Reads on stdin a bool *)
val bool: bool -> Process.t -> string -> bool
(* Time-stamp: <modified the 10/03/2019 (at 14:03) by Erwan Jahier> *)
(* Time-stamp: <modified the 13/03/2019 (at 16:59) by Erwan Jahier> *)
type t = {
......@@ -7,6 +7,7 @@ type t = {
mutable verbose: int;
mutable demon: Demon.t;
mutable rif: bool;
mutable ifi: bool;
mutable _args : (string * Arg.spec * string) list;
mutable _user_man : (string * string list) list;
......@@ -30,6 +31,7 @@ let (make_args : unit -> t) =
verbose = 0;
demon = Demon.Distributed;
rif = false;
ifi = false;
_args = [];
_user_man = [];
_hidden_man = [];
......@@ -105,6 +107,10 @@ let (mkoptab : t -> unit) =
(Arg.Unit(fun () -> args.rif <- true))
["Follows RIF conventions"];
mkopt opt ["--ignore-first-inputs"; "-ifi"]
(Arg.Unit(fun () -> args.ifi <- true))
["Ignore first inputs (necessary to use luciole via lurette/rdbg/luciole-rif)"];
mkopt opt ["--length";"-l"] ~arg:" <int>"
(Arg.Int (fun i -> args.length <- i))
["Maximum number of steps to be done (" ^ (string_of_int args.length) ^ " by default).\n"];
......
(* Time-stamp: <modified the 13/03/2019 (at 10:57) by Erwan Jahier> *)
(* Time-stamp: <modified the 13/03/2019 (at 18:04) by Erwan Jahier> *)
(* XXX Je pourrais utiliser Lwt pour rendre step non-bloquant, ce qui
permettrait d'accelerer la simu sur les machines qui ont plusieurs
......@@ -100,15 +100,16 @@ let rec (simu: int -> int -> Process.t list -> string ->
al::acc)
[] pl_n
in
let all = if custom then List.rev all else all in
assert (List.length pl = List.length all);
let all = List.rev all in
let enab_ll =
List.map2
(fun p al ->
let al = List.map (fun (_,_,a) -> a) al in
List.map (fun a_static -> List.mem a_static al) p.actions)
pl
all
if not custom then [] else
List.map2
(fun p al ->
let al = List.map (fun (_,_,a) -> a) al in
List.map (fun a_static -> List.mem a_static al) p.actions)
pl
all
in
let enable_val =
String.concat " " (List.map (fun b -> if b then "t" else "f")
......@@ -119,7 +120,9 @@ let rec (simu: int -> int -> Process.t list -> string ->
raise (Silent (n-i+1))
);
print_step n i e pl activate_val enable_val;
let next_activate_val, al = Demon.f SasArg.args.rif args.demon pl all enab_ll in
let next_activate_val, pnal =
Demon.f (SasArg.args.verbose > 1) args.demon pl all enab_ll
in
(* Do the steps *)
let lenv_list =
......@@ -127,18 +130,15 @@ let rec (simu: int -> int -> Process.t list -> string ->
let nl4algo = List.map (to_algo_neighbor e) nl in
let lenv = Env.get e p.pid in
p, p.step nl4algo lenv a)
al
pnal
in
(* update the env *)
let ne = List.fold_left update_env e lenv_list in
match all with
(* | [_] -> () *)
| [] -> assert false
| _ -> if i > 0 then simu n (i-1) pl next_activate_val pl_n ne else (
if SasArg.args.rif && custom then (
print_string "q\n"; flush stdout
))
if i > 0 then simu n (i-1) pl next_activate_val pl_n ne else (
if SasArg.args.rif then (
print_string "q\n"; flush stdout
))
let () =
( try SasArg.parse Sys.argv;
......@@ -168,7 +168,6 @@ let () =
let pl_n = List.combine pl neighors in
if !Algo.verbose_level > 0 then List.iter dump_process pl_n;
let n = SasArg.args.length in
let pl = List.rev pl in
if SasArg.args.rif then (
Printf.printf "#inputs %s\n"
(if SasArg.args.demon = Demon.Custom then (
......@@ -181,6 +180,13 @@ let () =
Printf.printf "#outputs %s\n" (StringOf.env_rif_decl pl);
flush stdout
);
if SasArg.args.ifi then (
List.iter
(fun p -> List.iter
(fun a -> ignore (RifRead.bool (args.verbose > 1) p a)) p.actions)
pl;
Printf.eprintf "Ignoring the first vectors of sasa inputs\n"; flush stderr;
);
simu n n pl "" pl_n e
with
| Dynlink.Error e -> Printf.printf "Error: %s\n" (Dynlink.error_message e)
......
(* Time-stamp: <modified the 21/02/2019 (at 11:31) by Erwan Jahier> *)
(* Time-stamp: <modified the 13/03/2019 (at 14:49) by Erwan Jahier> *)
open Graph
open Graph.Dot_ast
......@@ -108,7 +108,8 @@ let (do_stmt: bool -> node list -> Dot_ast.stmt -> node list) =
let (read: string -> t) = fun f ->
let dot_file = Graph.Dot.parse_dot_ast f in
assert (not dot_file.strict);
List.fold_left (do_stmt dot_file.digraph) [] dot_file.stmts
let res = List.fold_left (do_stmt dot_file.digraph) [] dot_file.stmts in
List.rev res
type neighbor = {
n_id: string;
......
# Time-stamp: <modified the 12/03/2019 (at 22:52) by Erwan Jahier>
# Time-stamp: <modified the 13/03/2019 (at 18:01) by Erwan Jahier>
test: test0 lurette0
test0: cmxs
......@@ -27,7 +27,7 @@ lurette: lurette0
manual:cmxs
lurette -o lurette.rif --sim2chro \
-sut "$(sasa) fig5.1-noinit.dot -custd -rif" \
-sut "$(sasa) fig5.1-noinit.dot -custd -rif -ifi" \
-env "lutin demon.lut -n manual" &&\
gnuplot-rif lurette.rif
......
# Time-stamp: <modified the 13/03/2019 (at 11:10) by Erwan Jahier>
# Time-stamp: <modified the 13/03/2019 (at 18:02) by Erwan Jahier>
test: test1 test2 lurette0
......@@ -18,7 +18,7 @@ gnuplot: ring.rif
gnuplot-rif $<
luciole:
luciole-rif $(sasa) ring.dot -custd -rif
luciole-rif $(sasa) ring.dot -custd -rif -ifi
lurette0:cmxs
lurette -o lurette.rif \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment