diff --git a/lib/sasacore/exhaustSearch.ml b/lib/sasacore/exhaustSearch.ml index a6e92a64ca9321371319405cb57c2694a17b94f6..264f5b40243383e3834e2a94da3fe4de3a003801 100644 --- a/lib/sasacore/exhaustSearch.ml +++ b/lib/sasacore/exhaustSearch.ml @@ -92,7 +92,7 @@ let (bnb : out_channel -> bool -> 'v ss -> List.map (fun al -> incr cpt; - if !cpt mod (st0.sasarg.length / 100) = 0 then + if !cpt mod (st0.sasarg.length / 100) = 0 && not st0.sasarg.quiet then Printf.printf "%d%% of steps have been tryied so far...\r%!" (!cpt / (st0.sasarg.length / 100)); let nst = Step.f al st in let pot_nst = pot nst in @@ -123,7 +123,8 @@ let (bnb : out_channel -> bool -> 'v ss -> stop = (fun _ _node -> if !cpt >= max_step then ( pf log "Max number of step reached (%d). Queue size=%d\n%!" !cpt !qsize; - pf stdout "Max number of step reached (%d). Queue size=%d\n%!" !cpt !qsize; + if not st0.sasarg.quiet then + pf stdout "Max number of step reached (%d). Queue size=%d\n%!" !cpt !qsize; true ) else false ); diff --git a/lib/sasacore/sasArg.ml b/lib/sasacore/sasArg.ml index 44238c5087d5f82408e099b9fad2b15440040b8f..8fb49d61e0804fc870dae890c89786092d55df7e 100644 --- a/lib/sasacore/sasArg.ml +++ b/lib/sasacore/sasArg.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 19/10/2021 (at 23:33) by Erwan Jahier> *) +(* Time-stamp: <modified the 08/11/2021 (at 10:53) by Erwan Jahier> *) type t = { @@ -174,7 +174,7 @@ let (mkoptab : string array -> t -> unit) = ["Generate simulation data in a file (use stdout otherwise)"]; mkopt args ["--seed";"-seed"] - (Arg.Int(fun i -> Seed.set i)) ~arg:" <int>" + (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"] @@ -215,6 +215,9 @@ let (mkoptab : string array -> t -> unit) = (Arg.Unit (fun _ -> (print_string (Sys.ocaml_version^"\n"); flush stdout; exit 0))) ["Display the version ocaml version sasa was compiled with and exit."]; + mkopt args ["--quiet";"-q"] + (Arg.Unit (fun () -> args.quiet <- true)) ["Set the quiet mode"]; + mkopt args ["--verbose";"-vl"] ~arg:" <int>" (Arg.Int (fun i -> args.verbose <- i)) ["Set the verbose level"]; diff --git a/lib/sasacore/seed.ml b/lib/sasacore/seed.ml index e99d63cf2f572708b32eb2deba25cfc4064e176d..211f98cf5f644cef3ef2f0644467d7d5fe92733d 100644 --- a/lib/sasacore/seed.ml +++ b/lib/sasacore/seed.ml @@ -1,10 +1,9 @@ -(* Time-stamp: <modified the 27/07/2021 (at 09:20) by Erwan Jahier> *) +(* Time-stamp: <modified the 08/11/2021 (at 10:53) by Erwan Jahier> *) let seed = ref None let replay_seed = ref false -let verbose = true -let set s = +let set ?verb:(verbose=true) s = if verbose then Printf.fprintf stderr " [sasa] The sasa random engine seed is set to %i\n%!" s; Random.init s; @@ -14,12 +13,12 @@ let seed_file_name label = Printf.sprintf "sasa-%s.seed" label (* for --replay *) -let reset_the_seed_to_last label = +let reset_the_seed_to_last ?verb:(verbose=true) label = let f = seed_file_name label in try let ic = open_in f in let seed = int_of_string (input_line ic) in - set seed; + set ~verb:verbose seed; Printf.eprintf " [sasa] Replay the sasa run using the seed in %s\n" f; flush stderr; true @@ -30,8 +29,8 @@ let reset_the_seed_to_last label = let reset () = seed := None -let rec (get : string -> int) = - fun label -> +let rec (get : ?verb:bool -> string -> int) = + fun ?verb:(verbose=true) label -> let label = Filename.basename label in match !seed with | Some i -> i @@ -40,7 +39,7 @@ let rec (get : string -> int) = - in -replay mode, we first try to read the seed in the seed file - otherwise, we create a random seed and save if into args, and into a file for -replay *) - if !replay_seed && reset_the_seed_to_last label then (get label) else ( + if !replay_seed && reset_the_seed_to_last ~verb:verbose label then (get label) else ( let seed = Random.self_init (); Random.int 1073741823 in let seed_file = seed_file_name label in let oc = open_out seed_file in @@ -48,6 +47,6 @@ let rec (get : string -> int) = (Mypervasives.entete "#" SasaVersion.str SasaVersion.sha); flush oc; close_out oc; - set seed; + set ~verb:verbose seed; seed ) diff --git a/lib/sasacore/seed.mli b/lib/sasacore/seed.mli index d69925d783007941f1356a5b38a8ee72629d8921..16f2515b0a1e69d09d9ef2366a3cc19950557847 100644 --- a/lib/sasacore/seed.mli +++ b/lib/sasacore/seed.mli @@ -1,10 +1,11 @@ -(* Time-stamp: <modified the 21/05/2021 (at 11:29) by Erwan Jahier> *) +(* Time-stamp: <modified the 08/11/2021 (at 10:53) by Erwan Jahier> *) -val set : int -> unit +(** [set verbose seed] *) +val set : ?verb:bool -> int -> unit val reset : unit -> unit (** The string is used to create a file name to save/restore the seed when the --replay option is used *) -val get : string -> int +val get : ?verb:bool -> string -> int val replay_seed : bool ref diff --git a/lib/sasacore/simuState.ml b/lib/sasacore/simuState.ml index d3ec6cf494ed69fdc95e7cbc7c019e9744d4d408..3fe54131a32bad6d9ef70931eaef5ce5bed9d6f2 100644 --- a/lib/sasacore/simuState.ml +++ b/lib/sasacore/simuState.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 16/10/2021 (at 14:55) by Erwan Jahier> *) +(* Time-stamp: <modified the 08/11/2021 (at 10:59) by Erwan Jahier> *) open Register open Topology @@ -193,7 +193,7 @@ let (make : bool -> string array -> 'v t) = flush stdout; exit 2 in - let seed = Seed.get args.topo in + let seed = Seed.get ~verb:(args.verbose>0) args.topo in try let dynlink = if args.output_algos then false else dynlink in let dot_file = args.topo in @@ -288,7 +288,7 @@ let (make : bool -> string array -> 'v t) = close_out oc; Printf.eprintf " [sasa] %s has been generated.\n%!" fn; exit 0); - if args.no_data_file then () else ( + if args.no_data_file || args.quiet then () else ( let oc = if args.rif then stderr else stdout in if !Register.verbose_level > 0 then Printf.eprintf "==> open rif file...\n%!"; if not args.rif then diff --git a/lib/sasacore/worstInit.ml b/lib/sasacore/worstInit.ml index fd6ba9171fdf155e984563a57d1984e7f5e44bad..a6f91a2b6a2804e3c8c94f086b2a240f8bb09012 100644 --- a/lib/sasacore/worstInit.ml +++ b/lib/sasacore/worstInit.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 22/10/2021 (at 10:48) by Erwan Jahier> *) +(* Time-stamp: <modified the 08/11/2021 (at 11:48) by Erwan Jahier> *) open Register @@ -224,7 +224,7 @@ let (fchc : out_channel -> ('v SimuState.t -> int) -> 'v SimuState.t -> int (* occurs if all successors are cut *) run_more psol more | LocalSearch.Stopped -> - Printf.printf "The worst initial configuration, which costs %d, is " psol.cost; + Printf.printf "\nThe worst initial configuration costs %d :" psol.cost; point_to_ss psol.st ss_init | LocalSearch.Sol (nsol, more) -> if nsol.cost > psol.cost then ( diff --git a/src/Makefile b/src/Makefile index c4f1f3c9b88d593f24e761c62e0d8e1ba583bca3..e4a157b7de91211e41377fd8b64c435218c69579 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,12 +1,8 @@ all: - dune build sasa.exe + cd .. ; make && make install -install: - dune build @install - clean: - rm -f *.cmxs sasa *.cmi *.o *.cmx *.pdf - dune clean + cd .. ; make clean diff --git a/src/sasaMain.ml b/src/sasaMain.ml index 0b96c75c856becb84da49a9dda747c4a3706fb3d..3b4bfa362bf85065b035ae1fe35fbc266032ba7d 100644 --- a/src/sasaMain.ml +++ b/src/sasaMain.ml @@ -12,28 +12,30 @@ let (print_step : out_channel -> 'v SimuState.t -> int -> int -> string -> strin (* Printf.fprintf log "%s %s %s %s\n%!" (StringOf.env_rif e pl) enable_val legitimate pot; *) ) else if args.no_data_file then ( - Printf.printf "\n#step %s\n%!" (string_of_int (n-i)) + if not args.quiet then Printf.printf "\n#step %s\n%!" (string_of_int (n-i)) ) else ( if args.daemon = DaemonType.Custom then ( (* in custom mode, to be able to talk with lurette, this should not be printed on stdout - *) - if not args.rif then ( + *) + if not args.rif && not args.quiet then ( Printf.eprintf "\n#step %s\n" (string_of_int (n-i)) ; Printf.eprintf "%s #outs " activate_val; flush stderr ); - Printf.printf "%s %s %s %s\n%!" (StringOf.env_rif e pl) enable_val legitimate pot; + if not args.quiet then + Printf.printf "%s %s %s %s\n%!" (StringOf.env_rif e pl) enable_val legitimate pot; ) else ( (* rif mode, internal daemons *) - if args.rif then - Printf.printf " %s %s %s %s %s\n%!" - (StringOf.env_rif e pl) enable_val activate_val legitimate pot - else ( - Printf.printf "\n#step %s\n" (string_of_int (n-i)); - Printf.printf "%s%s %s %s %s %s\n%!" - (if args.rif then "" else "#outs ") - (StringOf.env_rif e pl) enable_val activate_val legitimate pot - ); + if not args.quiet then ( + if args.rif then + Printf.printf " %s %s %s %s %s\n%!" + (StringOf.env_rif e pl) enable_val activate_val legitimate pot + else ( + Printf.printf "\n#step %s\n" (string_of_int (n-i)); + Printf.printf "%s%s %s %s %s %s\n%!" + (if args.rif then "" else "#outs ") + (StringOf.env_rif e pl) enable_val activate_val legitimate pot + )); ); flush stderr; flush stdout diff --git a/test/dijkstra-ring/ring.dot b/test/dijkstra-ring/ring.dot index 5e9d65a2f97b9b40eda1aa0fe6268a8da4332701..e2eb7c8d8789e83c7f0ce88b9cc0cf06253e7ecf 100644 --- a/test/dijkstra-ring/ring.dot +++ b/test/dijkstra-ring/ring.dot @@ -1,14 +1,14 @@ -digraph ring7 { - graph - - root [algo="root.ml" init="{root=1;c=1}" ] - p2 [algo="p.ml" init="{root=0;c=3}" ] - p3 [algo="p.ml" init="{root=0;c=3}" ] - p4 [algo="p.ml" init="{root=0;c=2}" ] - p5 [algo="p.ml" init="{root=0;c=2}" ] - p6 [algo="p.ml" init="{root=0;c=1}" ] - p7 [algo="p.ml" init="{root=0;c=1}" ] - p8 [algo="p.ml" init="{root=0;c=0}" ] +digraph ring { + + + root [algo="root.ml" init="{root=1;c=1}" ] + p2 [algo="p.ml" init="{root=0;c=3}" ] + p3 [algo="p.ml" init="{root=0;c=3}" ] + p4 [algo="p.ml" init="{root=0;c=2}" ] + p5 [algo="p.ml" init="{root=0;c=2}" ] + p6 [algo="p.ml" init="{root=0;c=1}" ] + p7 [algo="p.ml" init="{root=0;c=1}" ] + p8 [algo="p.ml" init="{root=0;c=0}" ] root -> p2 -> p3 -> p4 -> p5 -> p6 -> p7 -> p8 -> root }