Commit 9e402d87 authored by erwan's avatar erwan
Browse files

Merge branch 'init-search' into search

parents 492e65e3 f399592e
Pipeline #95121 failed with stages
in 3 minutes and 6 seconds
......@@ -11,8 +11,8 @@ build:
- opam repo add verimag-sync-repo "http://www-verimag.imag.fr/DIST-TOOLS/SYNCHRONE/opam-repository"
- eval `opam config env`
- sudo apt-get update
- opam depext -y lustre-v6 lutin lablgtk3
- opam install -y dune ocamlgraph lutin lablgtk3
- opam depext -y lustre-v6 lutin lablgtk3 functory psq
- opam install -y dune ocamlgraph lutin lablgtk3 functory psq
- make
- make install
- make test
......
......@@ -13,7 +13,7 @@ odoc:
dune build @doc
clean:
rm -f *.cmxs sasa *.cmi *.o *.cmx *.pdf
rm -f *.cmxs *.cmi *.o *.cmx *.pdf
rm -f lib/sasacore/sasaVersion.ml
dune clean
cd test; make clean
......
(lang dune 1.11)
(lang dune 2.0)
This diff is collapsed.
......@@ -51,10 +51,41 @@ make clean
cd test
cp -rf skeleton my_algo # copy a simple example
cd my_algo # one may want to edit "p.ml" and "ring.dot"
make ring.cmxs # compile anything that needs to be compiled
sasa ring.dot -l 4 # run a batch simulation for 4 steps
make ring.cmxs # compile anything that needs to be compiled
sasa ring.dot -l 4 # run a batch simulation for 4 steps
#+END_SRC
#+RESULTS[13cc60a20b534115483ffd7ae0f22f6bcc52a8dd]:
#+begin_example
sasa -reg ring.dot
ocamlfind ocamlopt -bin-annot -package algo -shared state.ml p.ml config.ml ring.ml -o ring.cmxs
# Automatically generated by /home/jahier/.opam/4.13.1/bin/sasa version "v4.5.7" ("733695a")
# on crevetete the 16/2/2022 at 18:26:44
#sasa ring.dot -l 4
#seed 178073955
#inputs
#outputs "p1_v0":int "p2_v0":int "p3_v0":int "p4_v0":int "p5_v0":int "p6_v0":int "p7_v0":int "Enab_p1_action1":bool "Enab_p1_action2":bool "Enab_p2_action1":bool "Enab_p2_action2":bool "Enab_p3_action1":bool "Enab_p3_action2":bool "Enab_p4_action1":bool "Enab_p4_action2":bool "Enab_p5_action1":bool "Enab_p5_action2":bool "Enab_p6_action1":bool "Enab_p6_action2":bool "Enab_p7_action1":bool "Enab_p7_action2":bool "p1_action1":bool "p1_action2":bool "p2_action1":bool "p2_action2":bool "p3_action1":bool "p3_action2":bool "p4_action1":bool "p4_action2":bool "p5_action1":bool "p5_action2":bool "p6_action1":bool "p6_action2":bool "p7_action1":bool "p7_action2":bool "legitimate":bool
#step 0
#outs 9 2 8 5 5 4 8 t f t f t f t f t f t f t f t f t f t f t f f f t f f f f
#step 1
#outs 0 0 0 0 5 0 8 t f f t f t t f f t t f f t f f f f f t t f f f f f f t f
#step 2
#outs 0 0 1 0 5 0 1 f f f f f t t f f t f f f t f f f f f f t f f t f f f f f
#step 3
#outs 0 0 1 0 1 0 1 f f f f f t f f f t f f f t f f f f f t f f f f f f f f f
#step 4
#outs 0 0 1 0 1 0 1 f f f f f t f f f t f f f t f f f f f f f f f f f f f t f
#q
#+end_example
+ [[https://gricad-gitlab.univ-grenoble-alpes.fr/verimag/synchrone/sasa][SASA source code]]
+ [[https://verimag.gricad-pages.univ-grenoble-alpes.fr/vtt/tags/sasa/][Some Online Tutorials]]
+ [[https://hal.archives-ouvertes.fr/hal-02521149][TAP 2020 article pre-print]]
......@@ -145,14 +176,15 @@ https://verimag.gricad-pages.univ-grenoble-alpes.fr/vtt/articles/sasa-gg/
The following has been generated from [[https://gricad-gitlab.univ-grenoble-alpes.fr/verimag/synchrone/sasa/blob/master/lib/algo/algo.mli][algo.mli]]
#+BEGIN_EXPORT html
#+begin_export html
<iframe title="The Algo API" name="algo-api"
width="700"
height="700"
src="https://verimag.gricad-pages.univ-grenoble-alpes.fr/synchrone/sasa/_html/algo/Algo/index.html"
alt="_html/algo/Algo/index.html";>
</iframe>
#+END_EXPORT
#+end_export
* Examples
......@@ -498,7 +530,7 @@ make rdbg
This make rule (defined in =Makefile= and =../Makefile.inc=)
1. generates the =ring.ml= file, that contains the registration code
(that can indeed be generated by sasa, as explained in =algo.mli=).
2. launches =rdbg= with some arguments (=rdbg -o ring.rif -sut "sasa ring.dot --locally-central-daemon"=).
2. launches =rdbg= with some arguments (=rdbg --sasa -o ring.rif -sut "sasa ring.dot --locally-central-daemon"=).
=rdbg= then prompts the user to
enter one of the following commands:
......@@ -573,7 +605,7 @@ that take advantage of the versatility (programmability) of
1. type =rdbg=
2. press enter to load the defaut session (=rdbg-session.ml=).
Then you can type:
3. =d= for displaying a (dynamic) dot graph with =dot=
3. =gv= (graph view) for displaying a (dynamic) dot graph with =dot=
4. or ALTERNATIVELY =ne= to use the =neato= layout engine (=tw=, =ci=,
=fd=, =sf=, =pa=, =os= to use the =twopi=, =circo=, =fdp=, =sfd=,
=patchwork=, =osage= layout engines respectively)
......@@ -698,7 +730,7 @@ the dot_view command as follows:
To install it:
#+BEGIN_SRC sh :eval no
opam depext -y rdbgui4ocaml
opam depext -y rdbgui4ocaml -- useless with opam >= 2.1
opam install -y rdbgui4ocaml
#+END_SRC
......@@ -708,38 +740,38 @@ To use it: https://verimag.gricad-pages.univ-grenoble-alpes.fr/vtt/articles/rdb
Some modules, used by the sasa core engine, can be useful from =rdbg=.
#+BEGIN_EXPORT html
#+begin_export html
<iframe title="The Topology API" name="topology-api"
width="700"
height="500"
src="https://verimag.gricad-pages.univ-grenoble-alpes.fr/synchrone/sasa/_html/sasacore/Sasacore/Topology/index.html"
alt="file:./_html/sasacore/Sasacore/Topology/index.html";>
</iframe>
#+END_EXPORT
#+BEGIN_EXPORT html
#+end_export
#+begin_export html
<iframe title="The Diameter API" name="diameter-api"
width="700"
height="300"
src="https://verimag.gricad-pages.univ-grenoble-alpes.fr/synchrone/sasa/_html/sasacore/Sasacore/Diameter/index.html"
alt="file:./_html/sasacore/Sasacore/Diameter/index.html";>
</iframe>
#+END_EXPORT
#+BEGIN_EXPORT html
#+end_export
#+begin_export html
<iframe title="The Process API"
width="700"
height="300"
src="https://verimag.gricad-pages.univ-grenoble-alpes.fr/synchrone/sasa/_html/sasacore/Sasacore/Process/index.html"
alt="file:./_html/sasacore/Sasacore/Process/index.html";>
</iframe>
#+END_EXPORT
#+BEGIN_EXPORT html
#+end_export
#+begin_export html
<iframe title="The StringOf API"
width="700"
height="300"
src="https://verimag.gricad-pages.univ-grenoble-alpes.fr/synchrone/sasa/_html/sasacore/Sasacore/StringOf/index.html"
alt="file:./_html/sasacore/Sasacore/StringOf/index.html";>
</iframe>
#+END_EXPORT
#+end_export
* Install
<<distributions>>
......@@ -775,7 +807,7 @@ opam install -y sasa
And optionally (to define test oracles in Lustre or daemons in Lutin):
#+BEGIN_SRC sh :eval no
opam depext -y rdbgui4sasa lutin
opam depext -y rdbgui4sasa lutin -- useless with opam >= 2.1
opam install -y rdbgui4sasa lutin lustre-v6
#+END_SRC
......@@ -786,8 +818,8 @@ mkdir ~/lv4 # for example
cd ~/lv4
wget http://www-verimag.imag.fr/DIST-TOOLS/SYNCHRONE/lustre-v4/distrib/linux64/lustre-v4-III-e-linux64.tgz
tar xvzf lustre-v4-III-e-linux64.tgz
echo "LUSTRE_INSTALL=~/lv4/lustre-v4-III-e-linux64" >> ~/.bashrc # if you are using bash
echo "PATH=$LUSTRE_INSTALL/bin:$PATH" >> ~/.bashrc
echo "export LUSTRE_INSTALL=~/lv4/lustre-v4-III-e-linux64" >> ~/.bashrc # if you are using bash
echo "export PATH=$LUSTRE_INSTALL/bin:$PATH" >> ~/.bashrc
sudo apt install -y wish
#+END_SRC
......@@ -834,8 +866,8 @@ mkdir ~/lv4 # for example
cd ~/lv4
wget http://www-verimag.imag.fr/DIST-TOOLS/SYNCHRONE/lustre-v4/distrib/linux64/lustre-v4-III-e-linux64.tgz
tar xvzf lustre-v4-III-e-linux64.tgz
echo "LUSTRE_INSTALL=~/lv4/lustre-v4-III-e-linux64" >> ~/.bashrc # if you are using bash
echo "PATH=$LUSTRE_INSTALL/bin:$PATH" >> ~/.bashrc
echo "export LUSTRE_INSTALL=~/lv4/lustre-v4-III-e-linux64" >> ~/.bashrc # if you are using bash
echo "export PATH=$LUSTRE_INSTALL/bin:$PATH" >> ~/.bashrc
sudo apt install -y wish
#+END_SRC
Otherwise:
......
......@@ -150,8 +150,8 @@ let (make_do: string array -> 'v SimuState.t -> RdbgPlugin.t) =
(get_action_value sl_in) Step.f
in
(* 3: Do the steps *)
let st = Sasacore.Step.f pnal st in
sasa_config := st.config;
let nst = Sasacore.Step.f pnal st in
sasa_config := nst.config;
("silent", Data.B silent)::("legitimate", Data.B legit)::pot_sl @
(from_sasa_env st) @ (get_sl_out true pl enab_ll) @
(get_sl_out false pl activate_val)
......
type ('n, 'tv, 'v) t = {
init : 'n * 'tv * 'v;
succ : 'n -> 'n list; (* returns (all or some) neighbors *)
is_goal : 'n -> bool; (* is the node a solution of the problem *)
stop : 'n -> 'n -> bool; (* [stop pre_sol n] to stop the search before all nodes are visited *)
cut: 'n -> 'n -> bool; (* if [cut pre_sol n] is true, stop exploring n *)
push : 'tv -> 'n -> 'tv; (* add the node in the set of nodes to visit *)
pop : 'tv -> ('n * 'tv) option; (* pick a node to visit *)
visiting : 'n -> 'v -> 'v; (* mark a node as visited *)
visited : 'n -> 'v -> bool; (* check if a node has been visited *)
}
type 'n sol = Stopped | NoMore | Sol of 'n * 'n moresol
and 'n moresol = 'n option -> 'n sol
let debug = false
let cut_nb = ref 0
let sol_nb = ref 0
let (run : ('n, 'tv, 'v) t -> 'n option -> 'n sol) =
fun g pre_sol ->
let cut sol_opt n = match sol_opt with
| None -> false
| Some sol ->
let res = g.cut sol n in
if res then incr cut_nb;
res
in
let pre_process sol_opt (v, tv) n =
if g.visited n v || cut sol_opt n then (v, tv) else (g.visiting n v, g.push tv n)
in
let rec loop ps n tv v psol =
let do_succ_cont s =
if g.stop ps n then Stopped else loop2 n tv v s
in (* to avoid code duplication *)
if not (g.is_goal n) then
do_succ_cont psol
else
(incr sol_nb; Sol(n, do_succ_cont))
and loop2 n tv v psol = (* look at the n successors *)
if debug then Printf.printf "look at successors\n%!";
let v, tv = List.fold_left (pre_process psol) (v, tv) (g.succ n) in
(match g.pop tv with
| None -> NoMore
| Some (next_n, tv) -> loop n next_n tv v psol
)
in
let n, tv, v = g.init in
loop n n tv v pre_sol
let stat log =
Printf.fprintf log "\n- local search stat:\n\t- cut: %d\n\t- sol nb: %d\n%!" !cut_nb !sol_nb
(* Time-stamp: <modified the 27/10/2021 (at 12:08) by Erwan Jahier> *)
(** A generic module to implement local searches
https://en.wikipedia.org/wiki/Local_search_(optimization)
*)
(** Parameterized by node, nodes to visit later, already visited (+ to visit) nodes
- 'tv: nodes to visit late can be implemented by lists, or priority queues
- 'v: visited nodes can be implemented by lists, or sets
*)
type ('n, 'tv, 'v) t = {
init : 'n * 'tv * 'v;
succ : 'n -> 'n list; (* returns (all or some) neighbors *)
is_goal : 'n -> bool; (* is the node a solution of the problem *)
stop : 'n -> 'n -> bool; (* if [stop pre_sol n], stop the search *)
cut: 'n -> 'n -> bool; (* if [cut pre_sol n], don't explore n *)
push : 'tv -> 'n -> 'tv; (* add the node in the set of nodes to visit *)
pop : 'tv -> ('n * 'tv) option; (* pick a node to visit *)
visiting : 'n -> 'v -> 'v; (* mark a node as visited *)
visited : 'n -> 'v -> bool; (* check if a node has been visited *)
}
type 'n sol = Stopped | NoMore | Sol of 'n * 'n moresol
and 'n moresol = 'n option -> 'n sol
(** [explore g] the graph induced by [g.succ] until either
- [pop tv]~>None, then it returns NoMore
- [stop pre_s s]~> true and is_goal s~>false, then it returns [Stopped]
- [is_goal s]~>true, then it returns [Sol(sol, cont)]
When a valid node (a.k.a., a solution) is found, [run] returns it plus
a continuation to carry on the search.
The optional argument of ['n moresol] ought to contain a previously obtained
solution (i.e., a node n for which [is_goal n=true]) that can be used by [cut]
to cut branches.
nb: no cost function is required. But of course, the [push] or the [cut]
functions might use one.
*)
val run : ('n, 'tv, 'v) t -> 'n moresol
val stat : out_channel -> unit
(* Time-stamp: <modified the 16/10/2021 (at 14:55) by Erwan Jahier> *)
(* Time-stamp: <modified the 31/03/2022 (at 17:13) by Erwan Jahier> *)
(** The module is used by
- the main sasa simulation loop (in ../../src/sasaMain.ml)
......@@ -24,7 +24,7 @@ type 'v enable_processes =
val get_enable_processes: 'v t -> 'v enable_processes
(** update the neighbors field using the config one *)
(** [update_config e c] updates c using e *)
val update_config: 'v Conf.t -> 'v t -> 'v t
(** Get pid's state and neighbors *)
......
# Automatically generated by /home/jahier/.opam/4.12.0/bin/sasa version "v4.5.2" ("6122a58")
# on crevetete the 28/7/2021 at 11:30:02
# Automatically generated by /home/jahier/.opam/4.13.1/bin/sasa version "v4.5.7" ("38972d1")
# on crevetete the 16/2/2022 at 18:52:06
#sasa -l 200 ring.dot -seed 42
#seed 42
......@@ -24,6 +24,4 @@
This algo is silent after 9 moves, 4 steps, 3 rounds.
q
#quit
%!
\ No newline at end of file
# Automatically generated by /home/jahier/.opam/4.12.0/bin/sasa version "v4.5.2" ("6122a58")
# on crevetete the 28/7/2021 at 11:30:02
# Automatically generated by /home/jahier/.opam/4.13.1/bin/sasa version "v4.5.7" ("38972d1")
# on crevetete the 16/2/2022 at 18:52:07
#sasa -l 200 grid4.dot -seed 42
#seed 42
......@@ -27,6 +27,4 @@
This algo is silent after 19 moves, 5 steps, 2 rounds.
q
#quit
%!
\ No newline at end of file
# Automatically generated by /home/jahier/.opam/4.13.1/bin/sasa version "v4.5.6" ("76c21c6")
# on crevetete the 6/10/2021 at 16:51:17
# Automatically generated by /home/jahier/.opam/4.13.1/bin/sasa version "v4.5.7" ("38972d1")
# on crevetete the 16/2/2022 at 18:54:08
#sasa g.dot -seed 42
#seed 42
......@@ -87,6 +87,4 @@
This algo is silent after 52 moves, 25 steps, 14 rounds.
q
#quit
%!
\ No newline at end of file
# Automatically generated by /home/jahier/.opam/4.13.1/bin/sasa version "v4.5.6" ("76c21c6")
# on crevetete the 6/10/2021 at 16:58:54
# Automatically generated by /home/jahier/.opam/4.13.1/bin/sasa version "v4.5.7" ("38972d1")
# on crevetete the 16/2/2022 at 18:55:07
#sasa ba100.dot -seed 42
#seed 42
......@@ -123,6 +123,4 @@
This algo is silent after 431 moves, 37 steps, 9 rounds.
q
#quit
%!
\ No newline at end of file
# Automatically generated by /home/jahier/.opam/4.13.1/bin/sasa version "v4.5.6" ("76c21c6")
# on crevetete the 6/10/2021 at 16:58:54
# Automatically generated by /home/jahier/.opam/4.13.1/bin/sasa version "v4.5.7" ("38972d1")
# on crevetete the 16/2/2022 at 18:55:07
#sasa er30.dot -seed 42
#seed 42
......@@ -84,6 +84,4 @@
This algo is silent after 114 moves, 24 steps, 11 rounds.
q
#quit
%!
\ No newline at end of file
# Automatically generated by /home/jahier/.opam/4.13.1/bin/sasa version "v4.5.6" ("76c21c6")
# on crevetete the 6/10/2021 at 16:58:54
# Automatically generated by /home/jahier/.opam/4.13.1/bin/sasa version "v4.5.7" ("38972d1")
# on crevetete the 16/2/2022 at 18:55:07
#sasa grid4.dot -seed 42
#seed 42
......@@ -102,6 +102,4 @@
This algo is silent after 72 moves, 30 steps, 15 rounds.
q
#quit
%!
\ No newline at end of file
# Automatically generated by /home/jahier/.opam/4.13.1/bin/sasa version "v4.5.6" ("76c21c6")
# on crevetete the 6/10/2021 at 16:58:54
# Automatically generated by /home/jahier/.opam/4.13.1/bin/sasa version "v4.5.7" ("38972d1")
# on crevetete the 16/2/2022 at 18:55:07
#sasa udg100.dot -seed 42
#seed 42
......@@ -102,6 +102,4 @@
This algo is silent after 460 moves, 30 steps, 9 rounds.
q
#quit
%!
\ No newline at end of file
# Automatically generated by /home/jahier/.opam/4.12.0/bin/sasa version "v4.5.2" ("6122a58")
# on crevetete the 28/7/2021 at 11:35:58
# Automatically generated by /home/jahier/.opam/4.13.1/bin/sasa version "v4.5.7" ("38972d1")
# on crevetete the 16/2/2022 at 18:56:31
#sasa te.dot -seed 42
#seed 42
......@@ -81,6 +81,4 @@
This algo is silent after 43 moves, 23 steps, 15 rounds.
q
#quit
%!
\ No newline at end of file
......@@ -81,7 +81,7 @@ let rdbg_get (cmd: string): string =
| None -> assert false
(** Compte le nombre de noeuds *)
let rdbg_count_nodes (): int =
let _rdbg_count_nodes (): int =
let cmd = " List.length (List.filter (fun (n,v) -> String.length n > 5 && String.sub n 0 5 = \"Enab_\") !e.outputs);;" in
let res = rdbg_get cmd in
(* rdbg renvoie une réponse qui ressemble à "- : int = 7" *)
......@@ -186,8 +186,8 @@ let update_rdbg_hook node activate =
()
(* GTK3 *)
let locale = GtkMain.Main.init ()
let thread = GtkThread.start()
let _locale = GtkMain.Main.init ()
let _thread = GtkThread.start()
let main () =
let window = GWindow.window ~width:320 ~height:240
~title:"Daemon GUI"
......
......@@ -7,13 +7,13 @@ open UdgUtils
open Sasacore
exception Incorrect_attribute
(* exception Incorrect_attribute *)
let min_max = ref None
let connected = ref None
let cyclic = ref None
let tree = ref None
let height:int option ref = ref None
(* let height:int option ref = ref None *)
let generate_du_dur graph plan_udg t : unit =
if (t.dotUDG <> "") then (
......
......@@ -160,9 +160,11 @@ let to_pdf engine par_var only_parent rn g f e =
(fun n ->
let l = g.succ n.id in
List.mapi (fun i t ->
if is_parent "par" n.id i e then
if g.directed then
Printf.sprintf "%s -> %s" t n.id
else if is_parent "par" n.id i e then
Printf.sprintf "%s -> %s" n.id t
else if n.id < t then
else if n.id < t then (* to avoid duplication in undir graphs *)
Printf.sprintf "%s -- %s" n.id t
else
Printf.sprintf "%s -- %s" t n.id
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment