From 0a3cdd00b23970eca4aeac25c89c695b510d2006 Mon Sep 17 00:00:00 2001
From: Erwan Jahier <erwan.jahier@univ-grenoble-alpes.fr>
Date: Wed, 11 Jan 2023 09:39:44 +0100
Subject: [PATCH] new: add a --gen-dot-at-legit

---
 lib/sasacore/sasArg.ml  | 68 ++++++++++++++++++++++-------------------
 lib/sasacore/sasArg.mli |  9 +++---
 2 files changed, 42 insertions(+), 35 deletions(-)

diff --git a/lib/sasacore/sasArg.ml b/lib/sasacore/sasArg.ml
index 8eaf4f60..7594b7db 100644
--- a/lib/sasacore/sasArg.ml
+++ b/lib/sasacore/sasArg.ml
@@ -1,7 +1,7 @@
-(* Time-stamp: <modified the 06/04/2022 (at 10:07) by Erwan Jahier> *)
+(* Time-stamp: <modified the 10/01/2023 (at 22:07) by Erwan Jahier> *)
 
 type init_search =
-   No_init_search | Local of int | Global of int  | Annealing of int 
+   No_init_search | Local of int | Global of int  | Annealing of int
 
 type t = {
   mutable topo: string;
@@ -14,29 +14,30 @@ type t = {
   mutable no_data_file: bool;
   mutable quiet: bool;
   mutable ifi: bool;
+  mutable gen_dot_at_legit: bool;
   mutable gen_lutin: bool;
   mutable gen_oracle: bool;
   mutable dummy_input: bool;
   mutable output_algos: bool;
   mutable gen_register: bool;
   mutable init_search: init_search;
-  
+
   mutable _args : (string * Arg.spec * string) list;
-  mutable _user_man  : (string * string list) list; 
-  mutable _hidden_man: (string * string list) list; 
+  mutable _user_man  : (string * string list) list;
+  mutable _hidden_man: (string * string list) list;
 
   mutable _others : string list;
   mutable _margin : int;
 }
 
-let usage_msg tool = ("usage: " ^ tool ^ " [<option>]* <topology>.dot 
+let usage_msg tool = ("usage: " ^ tool ^ " [<option>]* <topology>.dot
 use -h to see the available options.
 " )
 let print_usage tool = Printf.printf "%s\n" (usage_msg tool); flush stdout
 
 
-let (make_args : unit -> t) = 
-  fun () -> 
+let (make_args : unit -> t) =
+  fun () ->
     {
       topo = "";
       length = 10000;
@@ -48,15 +49,16 @@ let (make_args : unit -> t) =
       no_data_file = false;
       quiet = false;
       ifi = false;
+      gen_dot_at_legit = false;
       gen_lutin = false;
       gen_oracle = false;
       dummy_input = false;
       output_algos = false;
       gen_register = false;
       init_search = No_init_search;
-      _args = [];        
-      _user_man  = [];   
-      _hidden_man  = []; 
+      _args = [];
+      _user_man  = [];
+      _hidden_man  = [];
       _others = [];
       _margin =12;
     }
@@ -93,7 +95,7 @@ let (mkopt : t -> string list -> ?hide:bool -> ?arg:string -> Arg.spec ->
     let treto o = opt._args <- (o, se, "")::opt._args in
 	   List.iter treto ol ;
 	   let col1 = (String.concat ", " ol)^arg in
-	     if hide 
+	     if hide
         then opt._hidden_man <- (col1, ml)::opt._hidden_man
 	     else opt._user_man   <- (col1, ml)::opt._user_man
 
@@ -101,8 +103,8 @@ let myexit i = exit i
 (*******************************************************************************)
 
 (*** User Options Tab **)
-let (mkoptab : string array -> t -> unit) = 
-  fun argv args ->  
+let (mkoptab : string array -> t -> unit) =
+  fun argv args ->
     (
     mkopt args ["--length";"-l"] ~arg:" <int>"
       (Arg.Int (fun i -> args.length <- i))
@@ -116,7 +118,7 @@ let (mkoptab : string array -> t -> unit) =
     mkopt args  ["--central-daemon";"-cd"]
       (Arg.Unit(fun () -> args.daemon <- DaemonType.Central))
       ["Use a Central daemon (selects exactly one action)"];
-    
+
     mkopt args  ["--locally-central-daemon";"-lcd"]
       (Arg.Unit(fun () -> args.daemon <- DaemonType.LocallyCentral))
       ["Use a Locally Central daemon";
@@ -125,7 +127,7 @@ let (mkoptab : string array -> t -> unit) =
       (Arg.Unit(fun () -> args.daemon <- DaemonType.Distributed))
       ["Use a Distributed daemon (which select at least one action).";
        "This is the default daemon."];
-    
+
     mkopt args  ["--custom-daemon";"-custd"]
       (Arg.Unit(fun () -> args.daemon <- DaemonType.Custom;args.rif <- true))
       ["Use a Custom daemon (forces --rif)"];
@@ -185,10 +187,14 @@ let (mkoptab : string array -> t -> unit) =
       (Arg.String(fun fn -> args.output_file_name <- Some fn))
       ["Generate simulation data in a file (use stdout otherwise)"];
 
+   mkopt args ~hide:true ["--gen-dot-at-legit";"-gdal"]
+      (Arg.Unit(fun () -> args.gen_dot_at_legit <- true))
+      ["Generate a dot file initialised with the reached legitimate config"];
+
     mkopt args  ["--seed";"-seed"]
       (Arg.Int(fun i -> Seed.set ~verb:(args.verbose>0) i)) ~arg:" <int>"
       ["Set the pseudo-random generator seed of build-in daemons (wins over --replay)"];
-    
+
     mkopt args  ["--replay";"-replay"]
       (Arg.Unit(fun () -> Seed.replay_seed := true))
       ["Use the last generated seed to replay the last run"];
@@ -204,11 +210,11 @@ let (mkoptab : string array -> t -> unit) =
    mkopt args ~hide:true ["--list-algos";"-algo"]
      (Arg.Unit(fun () -> args.output_algos <- true))
       ["Output the algo files used in the dot file and exit. "];
-    
+
    mkopt args ~hide:true ["--gen-register";"-reg"]
      (Arg.Unit(fun () -> args.gen_register <- true))
       ["Generates the registering files and exit. "];
-    
+
    mkopt args ~hide:true ["--dummy-input"]
       (Arg.Unit(fun () -> args.dummy_input <- true))
       ["Add a dummy input to sasa so that built-in daemon can be used from rdbg"];
@@ -237,14 +243,14 @@ let (mkoptab : string array -> t -> unit) =
       (Arg.Unit (fun _ -> print_usage (argv.(0)); options args stdout; exit 0))
       ["Display main options"];
 
-    mkopt args ["--more";"-m"] (Arg.Unit (fun () -> more_options args stdout; exit 0)) 
+    mkopt args ["--more";"-m"] (Arg.Unit (fun () -> more_options args stdout; exit 0))
       ["Display more options"]
 
   )
 
 (* all unrecognized options are accumulated *)
 let (add_other : t -> string -> unit) =
-  fun opt s -> 
+  fun opt s ->
     opt._others <- s::opt._others
 
 let current = ref 0;;
@@ -272,21 +278,21 @@ let parse argv = (
     mkoptab argv args;
     Arg.parse_argv ~current:current argv args._args (add_other args) (usage_msg argv.(0));
     Functory.Cores.set_number_of_cores args.cores_nb;
-    (List.iter 
-       (fun f -> 
+    (List.iter
+       (fun f ->
           if (String.sub f 0 1 = "-") then
-            unexpected f 
+            unexpected f
           else if not (Sys.file_exists f) then
             file_notfound f
           else ()
-       ) 
+       )
        args._others);
     current := save_current;
     args.topo <- (match args._others with
-          [] -> 
+          [] ->
           Printf.fprintf stderr "*** The topology file is missing in '%s'\n%s\n"
-            (argv.(0)) (usage_msg argv.(0));  
-          exit 2; 
+            (argv.(0)) (usage_msg argv.(0));
+          exit 2;
         | x::_ -> x
       );
     args
@@ -294,8 +300,8 @@ let parse argv = (
   with
   | Arg.Bad msg ->
     Printf.fprintf stderr " [sasa] Error when calling '%s': %s\n%s\n%!" (argv.(0))
-      (first_line msg) (usage_msg argv.(0)); exit 2; 
-  | Arg.Help msg -> 
-    Printf.fprintf stdout "%s\n%s\n" msg (usage_msg argv.(0)); 
+      (first_line msg) (usage_msg argv.(0)); exit 2;
+  | Arg.Help msg ->
+    Printf.fprintf stdout "%s\n%s\n" msg (usage_msg argv.(0));
     exit 0
 )
diff --git a/lib/sasacore/sasArg.mli b/lib/sasacore/sasArg.mli
index ab229e78..eb764505 100644
--- a/lib/sasacore/sasArg.mli
+++ b/lib/sasacore/sasArg.mli
@@ -1,7 +1,7 @@
-(* Time-stamp: <modified the 06/04/2022 (at 09:32) by Erwan Jahier> *)
+(* Time-stamp: <modified the 10/01/2023 (at 22:08) by Erwan Jahier> *)
 
 type init_search =
-   No_init_search | Local of int | Global of int  | Annealing of int 
+   No_init_search | Local of int | Global of int  | Annealing of int
 
 type t = {
   mutable topo: string;
@@ -14,6 +14,7 @@ type t = {
   mutable no_data_file: bool;
   mutable quiet: bool;
   mutable ifi: bool;
+  mutable gen_dot_at_legit: bool;
   mutable gen_lutin: bool;
   mutable gen_oracle: bool;
   mutable dummy_input: bool;
@@ -22,8 +23,8 @@ type t = {
   mutable init_search: init_search;
 
   mutable _args : (string * Arg.spec * string) list;
-  mutable _user_man  : (string * string list) list; 
-  mutable _hidden_man: (string * string list) list; 
+  mutable _user_man  : (string * string list) list;
+  mutable _hidden_man: (string * string list) list;
 
   mutable _others : string list;
   mutable _margin : int;
-- 
GitLab