You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.4 KiB

2 months ago
  1. // synchronous leader election protocol (itai & Rodeh)
  2. // dxp/gxn 25/01/01
  3. dtmc
  4. // CONSTANTS
  5. const int N = 3; // number of processes
  6. const int K = 5; // range of probabilistic choice
  7. // counter module used to count the number of processes that have been read
  8. // and to know when a process has decided
  9. module counter
  10. // counter (c=i means process j reading process (i-1)+j next)
  11. c : [1..N-1];
  12. // reading
  13. [read] c<N-1 -> 1:(c'=c+1);
  14. // finished reading
  15. [read] c=N-1 -> 1:(c'=c);
  16. //decide
  17. [done] u1|u2|u3 -> 1:(c'=c);
  18. // pick again reset counter
  19. [retry] !(u1|u2|u3) -> 1:(c'=1);
  20. // loop (when finished to avoid deadlocks)
  21. [loop] s1=3 -> 1:(c'=c);
  22. endmodule
  23. // processes form a ring and suppose:
  24. // process 1 reads process 2
  25. // process 2 reads process 3
  26. // process 3 reads process 1
  27. module process1
  28. // local state
  29. s1 : [0..3];
  30. // s1=0 make random choice
  31. // s1=1 reading
  32. // s1=2 deciding
  33. // s1=3 finished
  34. // has a unique id so far (initially true)
  35. u1 : bool;
  36. // value to be sent to next process in the ring (initially sets this to its own value)
  37. v1 : [0..K-1];
  38. // random choice
  39. p1 : [0..K-1];
  40. // pick value
  41. [pick] s1=0 -> 1/K : (s1'=1) & (p1'=0) & (v1'=0) & (u1'=true)
  42. + 1/K : (s1'=1) & (p1'=1) & (v1'=1) & (u1'=true)
  43. + 1/K : (s1'=1) & (p1'=2) & (v1'=2) & (u1'=true)
  44. + 1/K : (s1'=1) & (p1'=3) & (v1'=3) & (u1'=true)
  45. + 1/K : (s1'=1) & (p1'=4) & (v1'=4) & (u1'=true);
  46. // read
  47. [read] s1=1 & u1 & c<N-1 -> 1:(u1'=(p1!=v2)) & (v1'=v2);
  48. [read] s1=1 & !u1 & c<N-1 -> 1:(u1'=false) & (v1'=v2) & (p1'=0);
  49. // read and move to decide
  50. [read] s1=1 & u1 & c=N-1 -> 1:(s1'=2) & (u1'=(p1!=v2)) & (v1'=0) & (p1'=0);
  51. [read] s1=1 & !u1 & c=N-1 -> 1:(s1'=2) & (u1'=false) & (v1'=0);
  52. // deciding
  53. // done
  54. [done] s1=2 -> 1:(s1'=3) & (u1'=false) & (v1'=0) & (p1'=0);
  55. //retry
  56. [retry] s1=2 -> 1:(s1'=0) & (u1'=false) & (v1'=0) & (p1'=0);
  57. // loop (when finished to avoid deadlocks)
  58. [loop] s1=3 -> 1:(s1'=3);
  59. endmodule
  60. // construct remaining processes through renaming
  61. module process2 = process1 [ s1=s2,p1=p2,v1=v2,u1=u2,v2=v3 ] endmodule
  62. module process3 = process1 [ s1=s3,p1=p3,v1=v3,u1=u3,v2=v1 ] endmodule
  63. // expected number of rounds
  64. rewards "num_rounds"
  65. [pick] true : 1;
  66. endrewards
  67. // labels
  68. label "elected" = s1=3&s2=3&s3=3;