From a1a7985b2e55128f9152add43ffa5b25c6f66502 Mon Sep 17 00:00:00 2001 From: Erwan Jahier <erwan.jahier@univ-grenoble-alpes.fr> Date: Wed, 15 Mar 2023 16:02:41 +0100 Subject: [PATCH] feat: add a --greedy-deterministic-central daemon --- lib/sasacore/daemon.ml | 6 +++--- lib/sasacore/daemonType.ml | 7 ++++--- lib/sasacore/evil.ml | 8 ++++---- lib/sasacore/evil.mli | 6 ++---- lib/sasacore/sasArg.ml | 8 ++++++-- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/sasacore/daemon.ml b/lib/sasacore/daemon.ml index cace17b5..75cd3bc0 100644 --- a/lib/sasacore/daemon.ml +++ b/lib/sasacore/daemon.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 25/01/2023 (at 16:47) by Erwan Jahier> *) +(* Time-stamp: <modified the 15/03/2023 (at 16:02) by Erwan Jahier> *) (* Enabled processes (with its enabling action + neighbors) *) type 'v pna = 'v Process.t * 'v Register.neighbor list * Register.action @@ -167,8 +167,8 @@ let (f: bool -> bool -> DaemonType.t -> 'v Process.t list -> | Greedy -> let al = Evil.greedy verbose_mode st pl neigbors_of_pid step nall in get_activate_val al pl, al - | GreedyCentral -> - let al = Evil.greedy_central verbose_mode st pl neigbors_of_pid step nall in + | (GreedyDetCentral|GreedyCentral) -> + let al = Evil.greedy_central verbose_mode (daemon=GreedyDetCentral) st pl neigbors_of_pid step nall in get_activate_val al pl, al | Bad i -> let al = Evil.bad i st nall in diff --git a/lib/sasacore/daemonType.ml b/lib/sasacore/daemonType.ml index a269c530..775236fe 100644 --- a/lib/sasacore/daemonType.ml +++ b/lib/sasacore/daemonType.ml @@ -1,17 +1,18 @@ -(* Time-stamp: <modified the 19/10/2021 (at 23:16) by Erwan Jahier> *) +(* Time-stamp: <modified the 15/03/2023 (at 15:59) by Erwan Jahier> *) type t = - | Synchronous (* select all actions *) + | Synchronous (* select all actions *) | Central (* select 1 action *) | LocallyCentral (* never activates two neighbors actions in the same step [1] *) | Distributed (* select at least one action *) | Custom (* enable/actions are communicated via stdin/stdout in RIF *) | Greedy (* always choose the set that maximize the potential function *) | GreedyCentral (* Ditto, but chooses one action only *) + | GreedyDetCentral (* Ditto, but with randomness *) | ExhaustSearch (* Explore all possible paths *) | ExhaustCentralSearch (* Explore all possible paths of central daemons *) - (* not yet implemented *) + (* not yet implemented *) | Bad of int (* try to choose the set actions that maximize the potential function but looking at sub-graphs of size N at max *) diff --git a/lib/sasacore/evil.ml b/lib/sasacore/evil.ml index f38c1efc..5e128d88 100644 --- a/lib/sasacore/evil.ml +++ b/lib/sasacore/evil.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 15/02/2023 (at 09:47) by Erwan Jahier> *) +(* Time-stamp: <modified the 15/03/2023 (at 16:01) by Erwan Jahier> *) type 'v pna = 'v Process.t * 'v Register.neighbor list * Register.action type 'v enabled = 'v pna list list @@ -136,10 +136,10 @@ let (greedy: bool -> 'v SimuState.t -> 'v Process.t list -> res (* val greedy_central: bool -> 'v Conf.t -> ('v Process.t * 'v Register.neighbor list) list -> *) -let (greedy_central: bool -> 'v SimuState.t -> 'v Process.t list -> +let (greedy_central: bool -> bool -> 'v SimuState.t -> 'v Process.t list -> ('v SimuState.t -> string -> 'v * ('v Register.neighbor * string) list) -> 'v step -> 'v pna list list -> 'v pna list) = - fun verb st pl neigbors_of_pid step all -> + fun verb det_greedy st pl neigbors_of_pid step all -> assert (all<>[]); match Register.get_potential () with | None -> failwith "No potential function has been provided" @@ -180,7 +180,7 @@ let (greedy_central: bool -> 'v SimuState.t -> 'v Process.t list -> let maxl_s = List.length maxl in if verb && maxl_s >1 then Printf.eprintf "[Evil.greedy]: %d choices have the same potentials\n%!" maxl_s; - List.nth maxl (Random.int maxl_s) + List.nth maxl (if det_greedy then 0 else Random.int maxl_s) in let res = fst (get_max all) in if verb then ( diff --git a/lib/sasacore/evil.mli b/lib/sasacore/evil.mli index 4ffc604b..c586a686 100644 --- a/lib/sasacore/evil.mli +++ b/lib/sasacore/evil.mli @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 31/07/2021 (at 09:15) by Erwan Jahier> *) +(* Time-stamp: <modified the 15/03/2023 (at 16:01) by Erwan Jahier> *) (** This module gathers daemons that tries to reach the worst case with @@ -18,7 +18,7 @@ val greedy: bool -> 'v SimuState.t -> 'v Process.t list -> (** Ditto, but for central daemons (of a connected component) *) val greedy_central: - bool -> 'v SimuState.t -> 'v Process.t list -> + bool -> bool -> 'v SimuState.t -> 'v Process.t list -> ('v SimuState.t -> string -> 'v * ('v Register.neighbor * string) list) -> 'v step -> 'v enabled -> 'v triggered @@ -29,5 +29,3 @@ val worst4convex: 'v SimuState.t -> 'v enabled -> 'v triggered (** enumerate all the cases (of length 1) in sub-graphs of given size (O(2^size_max)) *) val bad: int -> 'v SimuState.t -> 'v enabled -> 'v triggered - - diff --git a/lib/sasacore/sasArg.ml b/lib/sasacore/sasArg.ml index b41664ee..c4331d13 100644 --- a/lib/sasacore/sasArg.ml +++ b/lib/sasacore/sasArg.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 01/03/2023 (at 12:21) by Erwan Jahier> *) +(* Time-stamp: <modified the 15/03/2023 (at 15:59) by Erwan Jahier> *) type init_search = No_init_search | Local of int | Global of int | Annealing of int @@ -151,7 +151,11 @@ let (mkoptab : string array -> t -> unit) = mkopt args ["--greedy-central-daemon";"-gcd"] (Arg.Unit(fun () -> args.daemon <- DaemonType.GreedyCentral)) - ["Ditto, but restricted to central daemons. Performs |enabled| trials."]; + ["Ditto, but restricted to central daemons."]; + + mkopt args ["--greedy-deterministic-central-daemon";"-gdcd"] + (Arg.Unit(fun () -> args.daemon <- DaemonType.GreedyDetCentral)) + ["Ditto, but always return the same solution."]; mkopt args ["--exhaustive-daemon";"-ed"] (Arg.Unit(fun () -> args.daemon <- DaemonType.ExhaustSearch)) -- GitLab