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

test: add the Ghosh mutual exclusion algo in sasa/test/ and salut/sasa/test/

parent 319660d4
No related branches found
No related tags found
No related merge requests found
graph g {
p0 [algo="p0.ml"]
p1 [algo="p_last.ml"]
p1 -- p0
}
graph g8 {
p0 [algo="p0.ml"]
p1 [algo="p_even.ml"]
p2 [algo="p_odd.ml"]
p3 [algo="p_last.ml"]
p1 -- p0
p2 -- p1
p3 -- p2
p1 -- p3
p0 -- p2
}
graph g8 {
p0 [algo="p0.ml"]
p1 [algo="p_even.ml"]
p2 [algo="p_odd.ml"]
p3 [algo="p_even.ml"]
p4 [algo="p_odd.ml"]
p5 [algo="p_last.ml"]
p1 -- p0
p2 -- p1
p3 -- p2
p4 -- p3
p5 -- p4
p1 -- p3 -- p5
p0 -- p2 -- p4
}
graph g8 {
p0 [algo="p0.ml"]
p1 [algo="p_even.ml"]
p2 [algo="p_odd.ml"]
p3 [algo="p_even.ml"]
p4 [algo="p_odd.ml"]
p5 [algo="p_even.ml"]
p6 [algo="p_odd.ml"]
p7 [algo="p_last.ml"]
p1 -- p0
p2 -- p1
p3 -- p2
p4 -- p3
p5 -- p4
p6 -- p5
p7 -- p6
p1 -- p3 -- p5 --p7
p0 -- p2 -- p4 -- p6
}
(* Time-stamp: <modified the 31/05/2023 (at 16:51) by Erwan Jahier> *)
(* The Ghosh mutual exclusion algo: first node (a.k.a., bottom machine)
Sukumar Ghosh, Binary self-stabilization in distributed systems,
Information Processing Letters, Volume 40, Issue 3, 1991,Pages 153-159,
ISSN 0020-0190, https://doi.org/10.1016/0020-0190(91)90172-E. *)
open Algo
open State
let (init_state: int -> string -> t) =
fun _ _ -> { s = (Random.bool ()) ; kind = Bottom }
let (enable_f: t -> t neighbor list -> action list) =
fun s0 nl ->
let state n = (Algo.state n).s in
let s0 = s0.s in
match nl with
| [s1] | [s1; _] -> if s0 = not (state s1) then ["a"] else []
| _ -> failwith "invalid topology"
let (step_f : t -> t neighbor list -> action -> t ) =
fun s0 _nl _ ->
{ s0 with s = not s0.s }
(* Time-stamp: <modified the 31/05/2023 (at 16:51) by Erwan Jahier> *)
(* The Ghosh mutual exclusion algo: even nodes (a.k.a., y-machines)
Sukumar Ghosh, Binary self-stabilization in distributed systems,
Information Processing Letters, Volume 40, Issue 3, 1991,Pages 153-159,
ISSN 0020-0190, https://doi.org/10.1016/0020-0190(91)90172-E. *)
open Algo
open State
let (init_state: int -> string -> t) =
fun _ _ -> { s = (Random.bool ()) ; kind = Even }
let (enable_f: t -> t neighbor list -> action list) =
fun s1 nl ->
let state n = (Algo.state n).s in
let s1 = s1.s in
match List.map state nl with
| [s0; s2; s3] | [_;s0; s2; s3] -> if s0 = s1 && s1 = s2 && s3 = not s0 then ["a"] else []
| _ -> failwith "invalid topology"
let (step_f : t -> t neighbor list -> action -> t ) =
fun s0 _nl _ ->
{ s0 with s = not s0.s }
(* Time-stamp: <modified the 31/05/2023 (at 16:51) by Erwan Jahier> *)
(* The Ghosh mutual exclusion algo: last node (a.k.a., top machine)
Sukumar Ghosh, Binary self-stabilization in distributed systems,
Information Processing Letters, Volume 40, Issue 3, 1991,Pages 153-159,
ISSN 0020-0190, https://doi.org/10.1016/0020-0190(91)90172-E. *)
open Algo
open State
let (init_state: int -> string -> t) =
fun _ _ -> { s = (Random.bool ()) ; kind = Top }
let (enable_f: t -> t neighbor list -> action list) =
fun s2 nl ->
let state n = (Algo.state n).s in
let s2 = s2.s in
match nl with
| [_;s1] | [s1] -> if s2 = state s1 then ["a"] else []
| _ -> failwith "invalid topology"
let (step_f : t -> t neighbor list -> action -> t ) =
fun s0 _nl _ ->
{ s0 with s = not s0.s }
(* Time-stamp: <modified the 31/05/2023 (at 16:52) by Erwan Jahier> *)
(* The Ghosh mutual exclusion algo: odd nodes (a.k.a., x-machines)
Sukumar Ghosh, Binary self-stabilization in distributed systems,
Information Processing Letters, Volume 40, Issue 3, 1991,Pages 153-159,
ISSN 0020-0190, https://doi.org/10.1016/0020-0190(91)90172-E. *)
open Algo
open State
let (init_state: int -> string -> t) =
fun _ _ -> { s = (Random.bool ()) ; kind = Odd }
let (enable_f: t -> t neighbor list -> action list) =
fun s2 nl ->
let state n = (Algo.state n).s in
let s2 = s2.s in
match List.map state nl with
| [s0; s1; s3] | [s0; s1; s3; _] -> if s0=s1 && s1 = s3 && s2 = not s0 then ["a"] else []
| _ -> failwith "invalid topology"
let (step_f : t -> t neighbor list -> action -> t ) =
fun s0 _nl _ ->
{ s0 with s = not s0.s }
(* It is necessary to be able to distinguish between node kinds to
define the legitimate predicate
*)
type node_kind = Bottom | Odd | Even | Top
type t = { s : bool; kind : node_kind }
let to_string = (fun s -> Printf.sprintf "%b" s.s)
let of_string = Some (fun _ -> failwith "not yet implemented")
let copy x = x
let actions = ["a"]
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