Skip to content
Snippets Groups Projects
Commit 91a8c77c authored by erwan's avatar erwan
Browse files

Test: yet another bfs spanning tree construction

parent 68163d12
No related branches found
No related tags found
No related merge requests found
Showing
with 500 additions and 11 deletions
...@@ -19,5 +19,5 @@ B $OPAM_SWITCH_PREFIX/lib/ocaml ...@@ -19,5 +19,5 @@ B $OPAM_SWITCH_PREFIX/lib/ocaml
B $OPAM_SWITCH_PREFIX/lib/ocamlgraph B $OPAM_SWITCH_PREFIX/lib/ocamlgraph
B _build/default/src/.sasaMain.eobjs B _build/default/src/.sasaMain.eobjs
B _build/default/lib/algo/.algo.objs B _build/default/lib/algo/.algo.objs
B _build/default/lib/sasacore/.sascore.objs B _build/default/lib/sasacore/.sasacore.objs
...@@ -8,8 +8,8 @@ test: ...@@ -8,8 +8,8 @@ test:
cd bfs-spanning-tree/ && make cd bfs-spanning-tree/ && make
cd dfs/ && make cd dfs/ && make
cd dfs-list/ && make cd dfs-list/ && make
cd spanning-tree-central-daemon/ && make cd st-CYH91/ && make
cd bfs-st-HC92/ && make
echo "Every test went fine!" echo "Every test went fine!"
clean: clean:
...@@ -21,6 +21,7 @@ clean: ...@@ -21,6 +21,7 @@ clean:
cd bfs-spanning-tree/ && make clean cd bfs-spanning-tree/ && make clean
cd dfs/ && make clean cd dfs/ && make clean
cd dfs-list/ && make clean cd dfs-list/ && make clean
cd spanning-tree-central-daemon/ && make clean cd st-CYH91/ && make clean
cd bfs-st-HC92/ && make clean
-include Makefile.untracked -include Makefile.untracked
...@@ -7,7 +7,8 @@ The [test](https://gricad-gitlab.univ-grenoble-alpes.fr/verimag/synchrone/sasa/t ...@@ -7,7 +7,8 @@ The [test](https://gricad-gitlab.univ-grenoble-alpes.fr/verimag/synchrone/sasa/t
- `test/coloring/`: a graph coloring algorithm - `test/coloring/`: a graph coloring algorithm
- `test/alea-coloring/`: a randomized variant of the previous one - `test/alea-coloring/`: a randomized variant of the previous one
- `test/bfs-spanning-tree/`: a Breadth First Search Spanning tree construction - `test/bfs-spanning-tree/`: a Breadth First Search Spanning tree construction
- `test/spanning-tree-central-daemon`: another Spanning tree construction ("A self-stabilizing algorithm for constructing spanning trees" by Chen, Yu, and Huang in 1991) - `test/bfs-st-HC92`: another BFS Spanning tree construction ("A self-stabilizing algorithm for constructing breadth-first trees" by Huang and Chen in 1992)
- `test/st-CYH91`: another Spanning tree construction ("A self-stabilizing algorithm for constructing spanning trees" by Chen, Yu, and Huang in 1991)
- `test/dfs/`: a Depth First Search using arrays (the \`\`atomic state model'' version of a [Depth First Search algorithm proposed by Collin and Dolev in 1994](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.57.1100&rep=rep1&type=pdf)) - `test/dfs/`: a Depth First Search using arrays (the \`\`atomic state model'' version of a [Depth First Search algorithm proposed by Collin and Dolev in 1994](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.57.1100&rep=rep1&type=pdf))
- `test/dfs-list/`: a Depth First Search using lists - `test/dfs-list/`: a Depth First Search using lists
......
...@@ -12,8 +12,10 @@ Self-Stabilizing Algorithms'' By Altisen, Devismes, Dubois, and Petit. ...@@ -12,8 +12,10 @@ Self-Stabilizing Algorithms'' By Altisen, Devismes, Dubois, and Petit.
- =test/coloring/=: a graph coloring algorithm - =test/coloring/=: a graph coloring algorithm
- =test/alea-coloring/=: a randomized variant of the previous one - =test/alea-coloring/=: a randomized variant of the previous one
- =test/bfs-spanning-tree/=: a Breadth First Search Spanning tree construction - =test/bfs-spanning-tree/=: a Breadth First Search Spanning tree construction
- =test/spanning-tree-central-daemon=: another Spanning tree - =test/bfs-st-HC92=: another BFS Spanning tree construction ("A
construction ("A self-stabilizing algorithm for constructing self-stabilizing algorithm for constructing breadth-first trees" by
Huang and Chen in 1992)
- =test/st-CYH91=: another Spanning tree construction ("A self-stabilizing algorithm for constructing
spanning trees" by Chen, Yu, and Huang in 1991) spanning trees" by Chen, Yu, and Huang in 1991)
- =test/dfs/=: a Depth First Search using arrays (the ``atomic state - =test/dfs/=: a Depth First Search using arrays (the ``atomic state
model'' version of a [[http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.57.1100&rep=rep1&type=pdf][Depth First Search algorithm proposed by Collin and Dolev in 1994]]) model'' version of a [[http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.57.1100&rep=rep1&type=pdf][Depth First Search algorithm proposed by Collin and Dolev in 1994]])
......
# Time-stamp: <modified the 06/02/2020 (at 14:20) by Erwan Jahier>
test: test0 lurette
test0: ring.cmxs
sasa -l 200 ring.dot
sim2chrogtk: ring.rif
sim2chrogtk -ecran -in $< > /dev/null
gnuplot: ring.rif
gnuplot-rif $<
ocd: grid4.ml grid4.cma
rdbg --ocamldebug -sut "sasa grid4.dot" -l 1000
rdbg: grid4.ml
rdbg -o rdbg.rif -sut "sasa grid4.dot" -l 1000
rdbg10: grid10.ml
rdbg -o rdbg.rif -sut "sasa grid10.dot" -l 1000
lurette: grid4.cmxs
lurette -o rdbg.rif -sut "sasa grid4.dot" -l 1000
rdbg-ring: ring.ml
rdbg -o rdbg.rif -sut "sasa ring.dot" -l 1000
clean: genclean
rm -f ring.ml
-include ../Makefile.inc
-include Makefile.untracked
(* Time-stamp: <modified the 06/02/2020 (at 14:19) by Erwan Jahier> *)
(* A self-stabilizing algorithm for constructing breadth-first trees
Shing-Tsaan Huang, Nian-Shing Chen
Information Processing Letters 41(1992) 109-117 14 February 1992
Hyp:
- distributed daemon
- connected un-directed graph
*)
open Algo
open State
let (init_state: int -> 'st) =
fun i ->
{
level = 2+Random.int (n-1);
par = Random.int i;
}
let par_level (nl:State.t neighbor list) (e:State.t) : int =
let p = List.nth nl e.par in
let l_p = (state p).level in
l_p
let level n = (state n).level
let (enable_f: 'st -> 'st neighbor list -> action list) =
fun e nl ->
let l_i = e.level in (* level of the current node *)
let l_p = par_level nl e in (* level of its parent in the tree *)
if
(* (RO) l_i <> l_p+1 ^ l_p<n ---> l_i := l_p+1. *)
l_i <> l_p+1 && l_p < n
then ["R0"] else if
(* (Rl) Let k be a neighbor of i such that L(k) = min({L(j) s.t. j \in Nj),
l_p>L(k) ---> Li := L(k)+1 ; pi:=k.
. *)
let k = List.fold_left
(fun acc n -> if level acc < level n then acc else n)
(List.hd nl)
(List.tl nl)
in
l_p > level k
then ["R1"] else
[]
let rank k l = (* returns the rank of k in l *)
let rec aux i l =
match l with
| x::t -> if pid x = pid k then i else aux (i+1) t
| [] ->
Printf.eprintf "rank called with an element that is not in the list!\n%!";
exit 2
in
aux 0 l
let (step_f : 'st -> 'st neighbor list -> action -> 'st ) =
fun e nl a ->
(* Printf.printf "step_f [%s]\n%!" a; *)
match a with
| "R0" -> { e with level = 1 + par_level nl e }
| "R1" ->
let k = List.fold_left
(fun acc n -> if level acc < level n then acc else n)
(List.hd nl)
(List.tl nl)
in
{ level = 1 + level k ; par = rank k nl }
| _ -> e
let actions = Some ["R0";"R1"];
File moved
graph grid {
graph [min_deg=2
mean_deg=3.6
max_deg=4
is_connected=true
is_cyclic=true
is_tree=true
links_number=180]
p0 [algo="root.ml"]
p1 [algo="p.ml"]
p2 [algo="p.ml"]
p3 [algo="p.ml"]
p4 [algo="p.ml"]
p5 [algo="p.ml"]
p6 [algo="p.ml"]
p7 [algo="p.ml"]
p8 [algo="p.ml"]
p9 [algo="p.ml"]
p10 [algo="p.ml"]
p11 [algo="p.ml"]
p12 [algo="p.ml"]
p13 [algo="p.ml"]
p14 [algo="p.ml"]
p15 [algo="p.ml"]
p16 [algo="p.ml"]
p17 [algo="p.ml"]
p18 [algo="p.ml"]
p19 [algo="p.ml"]
p20 [algo="p.ml"]
p21 [algo="p.ml"]
p22 [algo="p.ml"]
p23 [algo="p.ml"]
p24 [algo="p.ml"]
p25 [algo="p.ml"]
p26 [algo="p.ml"]
p27 [algo="p.ml"]
p28 [algo="p.ml"]
p29 [algo="p.ml"]
p30 [algo="p.ml"]
p31 [algo="p.ml"]
p32 [algo="p.ml"]
p33 [algo="p.ml"]
p34 [algo="p.ml"]
p35 [algo="p.ml"]
p36 [algo="p.ml"]
p37 [algo="p.ml"]
p38 [algo="p.ml"]
p39 [algo="p.ml"]
p40 [algo="p.ml"]
p41 [algo="p.ml"]
p42 [algo="p.ml"]
p43 [algo="p.ml"]
p44 [algo="p.ml"]
p45 [algo="p.ml"]
p46 [algo="p.ml"]
p47 [algo="p.ml"]
p48 [algo="p.ml"]
p49 [algo="p.ml"]
p50 [algo="p.ml"]
p51 [algo="p.ml"]
p52 [algo="p.ml"]
p53 [algo="p.ml"]
p54 [algo="p.ml"]
p55 [algo="p.ml"]
p56 [algo="p.ml"]
p57 [algo="p.ml"]
p58 [algo="p.ml"]
p59 [algo="p.ml"]
p60 [algo="p.ml"]
p61 [algo="p.ml"]
p62 [algo="p.ml"]
p63 [algo="p.ml"]
p64 [algo="p.ml"]
p65 [algo="p.ml"]
p66 [algo="p.ml"]
p67 [algo="p.ml"]
p68 [algo="p.ml"]
p69 [algo="p.ml"]
p70 [algo="p.ml"]
p71 [algo="p.ml"]
p72 [algo="p.ml"]
p73 [algo="p.ml"]
p74 [algo="p.ml"]
p75 [algo="p.ml"]
p76 [algo="p.ml"]
p77 [algo="p.ml"]
p78 [algo="p.ml"]
p79 [algo="p.ml"]
p80 [algo="p.ml"]
p81 [algo="p.ml"]
p82 [algo="p.ml"]
p83 [algo="p.ml"]
p84 [algo="p.ml"]
p85 [algo="p.ml"]
p86 [algo="p.ml"]
p87 [algo="p.ml"]
p88 [algo="p.ml"]
p89 [algo="p.ml"]
p90 [algo="p.ml"]
p91 [algo="p.ml"]
p92 [algo="p.ml"]
p93 [algo="p.ml"]
p94 [algo="p.ml"]
p95 [algo="p.ml"]
p96 [algo="p.ml"]
p97 [algo="p.ml"]
p98 [algo="p.ml"]
p99 [algo="p.ml"]
p0 -- p1
p0 -- p10
p1 -- p11
p1 -- p2
p10 -- p11
p10 -- p20
p11 -- p12
p11 -- p21
p12 -- p13
p12 -- p2
p12 -- p22
p13 -- p14
p13 -- p23
p13 -- p3
p14 -- p15
p14 -- p24
p14 -- p4
p15 -- p16
p15 -- p25
p15 -- p5
p16 -- p17
p16 -- p26
p16 -- p6
p17 -- p18
p17 -- p27
p17 -- p7
p18 -- p19
p18 -- p28
p18 -- p8
p19 -- p29
p19 -- p9
p2 -- p3
p20 -- p21
p20 -- p30
p21 -- p22
p21 -- p31
p22 -- p23
p22 -- p32
p23 -- p24
p23 -- p33
p24 -- p25
p24 -- p34
p25 -- p26
p25 -- p35
p26 -- p27
p26 -- p36
p27 -- p28
p27 -- p37
p28 -- p29
p28 -- p38
p29 -- p39
p3 -- p4
p30 -- p31
p30 -- p40
p31 -- p32
p31 -- p41
p32 -- p33
p32 -- p42
p33 -- p34
p33 -- p43
p34 -- p35
p34 -- p44
p35 -- p36
p35 -- p45
p36 -- p37
p36 -- p46
p37 -- p38
p37 -- p47
p38 -- p39
p38 -- p48
p39 -- p49
p4 -- p5
p40 -- p41
p40 -- p50
p41 -- p42
p41 -- p51
p42 -- p43
p42 -- p52
p43 -- p44
p43 -- p53
p44 -- p45
p44 -- p54
p45 -- p46
p45 -- p55
p46 -- p47
p46 -- p56
p47 -- p48
p47 -- p57
p48 -- p49
p48 -- p58
p49 -- p59
p5 -- p6
p50 -- p51
p50 -- p60
p51 -- p52
p51 -- p61
p52 -- p53
p52 -- p62
p53 -- p54
p53 -- p63
p54 -- p55
p54 -- p64
p55 -- p56
p55 -- p65
p56 -- p57
p56 -- p66
p57 -- p58
p57 -- p67
p58 -- p59
p58 -- p68
p59 -- p69
p6 -- p7
p60 -- p61
p60 -- p70
p61 -- p62
p61 -- p71
p62 -- p63
p62 -- p72
p63 -- p64
p63 -- p73
p64 -- p65
p64 -- p74
p65 -- p66
p65 -- p75
p66 -- p67
p66 -- p76
p67 -- p68
p67 -- p77
p68 -- p69
p68 -- p78
p69 -- p79
p7 -- p8
p70 -- p71
p70 -- p80
p71 -- p72
p71 -- p81
p72 -- p73
p72 -- p82
p73 -- p74
p73 -- p83
p74 -- p75
p74 -- p84
p75 -- p76
p75 -- p85
p76 -- p77
p76 -- p86
p77 -- p78
p77 -- p87
p78 -- p79
p78 -- p88
p79 -- p89
p8 -- p9
p80 -- p81
p80 -- p90
p81 -- p82
p81 -- p91
p82 -- p83
p82 -- p92
p83 -- p84
p83 -- p93
p84 -- p85
p84 -- p94
p85 -- p86
p85 -- p95
p86 -- p87
p86 -- p96
p87 -- p88
p87 -- p97
p88 -- p89
p88 -- p98
p89 -- p99
p90 -- p91
p91 -- p92
p92 -- p93
p93 -- p94
p94 -- p95
p95 -- p96
p96 -- p97
p97 -- p98
p98 -- p99
}
graph g {
p0 [algo="p.ml" ]
p1 [algo="p.ml" ]
p2 [algo="p.ml" ]
p3 [algo="p.ml" ]
p4 [algo="root.ml" ]
p5 [algo="p.ml" ]
p6 [algo="p.ml" ]
p7 [algo="p.ml" ]
p8 [algo="p.ml" ]
p9 [algo="p.ml" ]
p10 [algo="p.ml" ]
p11 [algo="p.ml" ]
p12 [algo="p.ml" ]
p13 [algo="p.ml" ]
p14 [algo="p.ml" ]
p15 [algo="p.ml" ]
p0 -- p1 -- p2 -- p3 -- p7
p0 -- p4 -- p5 -- p6
p11-- p15
p1 -- p5 -- p9
p10 -- p11 -- p7
p10 -- p14 -- p15
p10 -- p6
p10 -- p9
p12 -- p13 -- p14
p12 -- p8 -- p9
p13 -- p9
p2 -- p6 -- p7
p4 -- p8
}
#use "../my-rdbg-tuning.ml";;
dot_view := sf;;
(* Time-stamp: <modified the 06/02/2020 (at 11:29) by Erwan Jahier> *) (* Time-stamp: <modified the 06/02/2020 (at 13:05) by Erwan Jahier> *)
(* "A self-stabilizing algorithm for constructing spanning trees" (* "A self-stabilizing algorithm for constructing spanning trees"
Nian-Shing Chen, Wey-Pyng Yu and Shing-Tsaan Huang Nian-Shing Chen, Wey-Pyng Yu and Shing-Tsaan Huang
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
Hyp: Hyp:
- central daemon - central daemon
- connected unidirected graph - connected un-directed graph
*) *)
...@@ -16,8 +16,8 @@ open State ...@@ -16,8 +16,8 @@ open State
let (init_state: int -> 'st) = let (init_state: int -> 'st) =
fun i -> fun i ->
{ {
level = (try Random.int n with _ -> failwith (Printf.sprintf "level: Random.int %d" n)); level = Random.int n;
par = try Random.int i with _ -> failwith (Printf.sprintf "par: Random.int %d" i); par = Random.int i;
} }
let par_level (nl:State.t neighbor list) (e:State.t) : int = let par_level (nl:State.t neighbor list) (e:State.t) : int =
......
File moved
(* Time-stamp: <modified the 04/02/2020 (at 11:06) by Erwan Jahier> *)
(* "A self-stabilizing algoritm for constructing spanning trees"
Nian-Shing Chen, Wey-Pyng Yu and Shing-Tsaan Huang
Information Processing Letters 39 (1991) 147-151
Hyp:
- central daemon
- connected unidirected graph
*)
let (init_state: int -> 'st) =
fun i ->
{
State.level = 0;
State.par = -1;
}
(* The root is never enabled... *)
let enable_f = fun _ _ -> []
(* ... nor activated! *)
let step_f = fun e _nl _a -> e
let actions = Some [];
let n = Algo.card()
type t = { level: int; par:int }
let to_string = (fun s -> Printf.sprintf "level=%i par=%i" s.level s.par)
let of_string = Some
(fun s ->
Scanf.sscanf s "{level=%d;par=%d}" (fun d par -> { level = d; par = par}))
let copy x = x
let print fmt s =
Format.pp_print_string fmt (to_string s)
let print_neighbor =
Algo.fmt_print_neighbor
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