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.

90 lines
2.7 KiB

  1. // synchronous leader election protocol (itai & Rodeh)
  2. // dxp/gxn 25/01/01
  3. dtmc
  4. // CONSTANTS
  5. const int N = 5; // number of processes
  6. const int K = 8; // 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 -> (c'=c+1);
  14. // finished reading
  15. [read] c=N-1 -> (c'=c);
  16. //decide
  17. [done] u1|u2|u3|u4|u5 -> (c'=c);
  18. // pick again reset counter
  19. [retry] !(u1|u2|u3|u4|u5) -> (c'=1);
  20. // loop (when finished to avoid deadlocks)
  21. [loop] s1=3 -> (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. + 1/K : (s1'=1) & (p1'=5) & (v1'=5) & (u1'=true)
  47. + 1/K : (s1'=1) & (p1'=6) & (v1'=6) & (u1'=true)
  48. + 1/K : (s1'=1) & (p1'=7) & (v1'=7) & (u1'=true);
  49. // read
  50. [read] s1=1 & u1 & c<N-1 -> (u1'=(p1!=v2)) & (v1'=v2);
  51. [read] s1=1 & !u1 & c<N-1 -> (u1'=false) & (v1'=v2) & (p1'=0);
  52. // read and move to decide
  53. [read] s1=1 & u1 & c=N-1 -> (s1'=2) & (u1'=(p1!=v2)) & (v1'=0) & (p1'=0);
  54. [read] s1=1 & !u1 & c=N-1 -> (s1'=2) & (u1'=false) & (v1'=0);
  55. // deciding
  56. // done
  57. [done] s1=2 -> (s1'=3) & (u1'=false) & (v1'=0) & (p1'=0);
  58. //retry
  59. [retry] s1=2 -> (s1'=0) & (u1'=false) & (v1'=0) & (p1'=0);
  60. // loop (when finished to avoid deadlocks)
  61. [loop] s1=3 -> (s1'=3);
  62. endmodule
  63. // construct remaining processes through renaming
  64. module process2 = process1 [ s1=s2,p1=p2,v1=v2,u1=u2,v2=v3 ] endmodule
  65. module process3 = process1 [ s1=s3,p1=p3,v1=v3,u1=u3,v2=v4 ] endmodule
  66. module process4 = process1 [ s1=s4,p1=p4,v1=v4,u1=u4,v2=v5 ] endmodule
  67. module process5 = process1 [ s1=s5,p1=p5,v1=v5,u1=u5,v2=v1 ] endmodule
  68. // expected number of rounds
  69. rewards "num_rounds"
  70. [pick] true : 1;
  71. endrewards
  72. // labels
  73. label "elected" = s1=3&s2=3&s3=3&s4=3&s5=3;