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

Update: compute the move and round numbers in batch (core) mode.

parent 84a18208
No related branches found
No related tags found
No related merge requests found
......@@ -31,17 +31,34 @@ let (print_step : int -> int -> SasArg.t -> 'v Env.t -> 'v Process.t list -> str
)
exception Silent of int
let moves = ref 0
let rounds = ref 0
let round_mask = ref []
let (update_round : bool list list -> bool list list -> unit) =
fun acti_ll enab_ll ->
if !round_mask = [] then round_mask := enab_ll;
round_mask := List.map2 (List.map2 (&&)) !round_mask enab_ll;
round_mask := List.map2 (List.map2 (fun m a -> m && not a)) !round_mask acti_ll;
if List.for_all (List.for_all (not)) !round_mask then (
round_mask := enab_ll;
incr rounds
);
()
let (simustep: int -> int -> SasArg.t -> string ->
('v Process.t * 'v Register.neighbor list) list -> 'v Env.t -> 'v Env.t * string) =
fun n i args activate_val pl_n e ->
(* 1: Get enable processes *)
let all, enab_ll = Sasacore.Main.get_enable_processes pl_n e in
let pl = fst(List.split pl_n) in
List.iter (List.iter (fun b -> if b then incr moves)) enab_ll;
if
not (args.rif) && List.for_all (fun b -> not b) (List.flatten enab_ll)
then (
print_step n i args e pl activate_val enab_ll;
incr rounds;
raise (Silent (n-i+1))
) else
if args.daemon = Daemon.Custom then
......@@ -51,6 +68,7 @@ let (simustep: int -> int -> SasArg.t -> string ->
let next_activate_val, pnal = Daemon.f args.dummy_input
(args.verbose > 1) args.daemon pl all enab_ll get_action_value
in
update_round next_activate_val enab_ll;
let next_activate_val =
String.concat " "
(List.map
......@@ -68,11 +86,10 @@ let (simustep: int -> int -> SasArg.t -> string ->
let rec (simuloop: int -> int -> SasArg.t -> string ->
('v Process.t * 'v Register.neighbor list) list -> 'v Env.t -> unit) =
fun n i args activate_val pl_n e ->
let ne, next_activate_val = simustep n i args activate_val pl_n e in
if i > 0 then simuloop n (i-1) args next_activate_val pl_n ne else (
print_string "#q\n"; flush stdout
)
let ne, next_activate_val = simustep n i args activate_val pl_n e in
if i > 0 then simuloop n (i-1) args next_activate_val pl_n ne else (
print_string "#q\n"; flush stdout
)
let () =
let args, pl_n, e = Sasacore.Main.make true Sys.argv in
......@@ -83,7 +100,8 @@ let () =
| Failure msg -> Printf.eprintf " [sasa] Error: %s\n%!" msg
| Silent i ->
let str = if args.rif then "#" else "" in
Printf.eprintf "\n%sThis algo is silent after %i steps\n" str i ;
Printf.eprintf "\n%sThis algo is silent after %i moves, %i steps, %i rounds.\n"
str !moves i !rounds;
flush stderr;
flush stdout;
print_string "\n#quit\n";
......
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