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.

183 lines
5.3 KiB

  1. <<<<<<< HEAD
  2. // synchronous leader election protocol (itai & Rodeh)
  3. // dxp/gxn 25/01/01
  4. dtmc
  5. // CONSTANTS
  6. const int N = 5; // number of processes
  7. const int K = 8; // range of probabilistic choice
  8. // counter module used to count the number of processes that have been read
  9. // and to know when a process has decided
  10. module counter
  11. // counter (c=i means process j reading process (i-1)+j next)
  12. c : [1..N-1];
  13. // reading
  14. [read] c<N-1 -> (c'=c+1);
  15. // finished reading
  16. [read] c=N-1 -> (c'=c);
  17. //decide
  18. [done] u1|u2|u3|u4|u5 -> (c'=c);
  19. // pick again reset counter
  20. [retry] !(u1|u2|u3|u4|u5) -> (c'=1);
  21. // loop (when finished to avoid deadlocks)
  22. [loop] s1=3 -> (c'=c);
  23. endmodule
  24. // processes form a ring and suppose:
  25. // process 1 reads process 2
  26. // process 2 reads process 3
  27. // process 3 reads process 1
  28. module process1
  29. // local state
  30. s1 : [0..3];
  31. // s1=0 make random choice
  32. // s1=1 reading
  33. // s1=2 deciding
  34. // s1=3 finished
  35. // has a unique id so far (initially true)
  36. u1 : bool;
  37. // value to be sent to next process in the ring (initially sets this to its own value)
  38. v1 : [0..K-1];
  39. // random choice
  40. p1 : [0..K-1];
  41. // pick value
  42. [pick] s1=0 -> 1/K : (s1'=1) & (p1'=0) & (v1'=0) & (u1'=true)
  43. + 1/K : (s1'=1) & (p1'=1) & (v1'=1) & (u1'=true)
  44. + 1/K : (s1'=1) & (p1'=2) & (v1'=2) & (u1'=true)
  45. + 1/K : (s1'=1) & (p1'=3) & (v1'=3) & (u1'=true)
  46. + 1/K : (s1'=1) & (p1'=4) & (v1'=4) & (u1'=true)
  47. + 1/K : (s1'=1) & (p1'=5) & (v1'=5) & (u1'=true)
  48. + 1/K : (s1'=1) & (p1'=6) & (v1'=6) & (u1'=true)
  49. + 1/K : (s1'=1) & (p1'=7) & (v1'=7) & (u1'=true);
  50. // read
  51. [read] s1=1 & u1 & c<N-1 -> (u1'=(p1!=v2)) & (v1'=v2);
  52. [read] s1=1 & !u1 & c<N-1 -> (u1'=false) & (v1'=v2) & (p1'=0);
  53. // read and move to decide
  54. [read] s1=1 & u1 & c=N-1 -> (s1'=2) & (u1'=(p1!=v2)) & (v1'=0) & (p1'=0);
  55. [read] s1=1 & !u1 & c=N-1 -> (s1'=2) & (u1'=false) & (v1'=0);
  56. // deciding
  57. // done
  58. [done] s1=2 -> (s1'=3) & (u1'=false) & (v1'=0) & (p1'=0);
  59. //retry
  60. [retry] s1=2 -> (s1'=0) & (u1'=false) & (v1'=0) & (p1'=0);
  61. // loop (when finished to avoid deadlocks)
  62. [loop] s1=3 -> (s1'=3);
  63. endmodule
  64. // construct remaining processes through renaming
  65. module process2 = process1 [ s1=s2,p1=p2,v1=v2,u1=u2,v2=v3 ] endmodule
  66. module process3 = process1 [ s1=s3,p1=p3,v1=v3,u1=u3,v2=v4 ] endmodule
  67. module process4 = process1 [ s1=s4,p1=p4,v1=v4,u1=u4,v2=v5 ] endmodule
  68. module process5 = process1 [ s1=s5,p1=p5,v1=v5,u1=u5,v2=v1 ] endmodule
  69. // expected number of rounds
  70. rewards "num_rounds"
  71. [pick] true : 1;
  72. endrewards
  73. // labels
  74. label "elected" = s1=3&s2=3&s3=3&s4=3&s5=3;
  75. =======
  76. // synchronous leader election protocol (itai & Rodeh)
  77. // dxp/gxn 25/01/01
  78. dtmc
  79. // CONSTANTS
  80. const int N = 5; // number of processes
  81. const int K = 8; // range of probabilistic choice
  82. // counter module used to count the number of processes that have been read
  83. // and to know when a process has decided
  84. module counter
  85. // counter (c=i means process j reading process (i-1)+j next)
  86. c : [1..N-1];
  87. // reading
  88. [read] c<N-1 -> (c'=c+1);
  89. // finished reading
  90. [read] c=N-1 -> (c'=c);
  91. //decide
  92. [done] u1|u2|u3|u4|u5 -> (c'=c);
  93. // pick again reset counter
  94. [retry] !(u1|u2|u3|u4|u5) -> (c'=1);
  95. // loop (when finished to avoid deadlocks)
  96. [loop] s1=3 -> (c'=c);
  97. endmodule
  98. // processes form a ring and suppose:
  99. // process 1 reads process 2
  100. // process 2 reads process 3
  101. // process 3 reads process 1
  102. module process1
  103. // local state
  104. s1 : [0..3];
  105. // s1=0 make random choice
  106. // s1=1 reading
  107. // s1=2 deciding
  108. // s1=3 finished
  109. // has a unique id so far (initially true)
  110. u1 : bool;
  111. // value to be sent to next process in the ring (initially sets this to its own value)
  112. v1 : [0..K-1];
  113. // random choice
  114. p1 : [0..K-1];
  115. // pick value
  116. [pick] s1=0 -> 1/K : (s1'=1) & (p1'=0) & (v1'=0) & (u1'=true)
  117. + 1/K : (s1'=1) & (p1'=1) & (v1'=1) & (u1'=true)
  118. + 1/K : (s1'=1) & (p1'=2) & (v1'=2) & (u1'=true)
  119. + 1/K : (s1'=1) & (p1'=3) & (v1'=3) & (u1'=true)
  120. + 1/K : (s1'=1) & (p1'=4) & (v1'=4) & (u1'=true)
  121. + 1/K : (s1'=1) & (p1'=5) & (v1'=5) & (u1'=true)
  122. + 1/K : (s1'=1) & (p1'=6) & (v1'=6) & (u1'=true)
  123. + 1/K : (s1'=1) & (p1'=7) & (v1'=7) & (u1'=true);
  124. // read
  125. [read] s1=1 & u1 & c<N-1 -> (u1'=(p1!=v2)) & (v1'=v2);
  126. [read] s1=1 & !u1 & c<N-1 -> (u1'=false) & (v1'=v2) & (p1'=0);
  127. // read and move to decide
  128. [read] s1=1 & u1 & c=N-1 -> (s1'=2) & (u1'=(p1!=v2)) & (v1'=0) & (p1'=0);
  129. [read] s1=1 & !u1 & c=N-1 -> (s1'=2) & (u1'=false) & (v1'=0);
  130. // deciding
  131. // done
  132. [done] s1=2 -> (s1'=3) & (u1'=false) & (v1'=0) & (p1'=0);
  133. //retry
  134. [retry] s1=2 -> (s1'=0) & (u1'=false) & (v1'=0) & (p1'=0);
  135. // loop (when finished to avoid deadlocks)
  136. [loop] s1=3 -> (s1'=3);
  137. endmodule
  138. // construct remaining processes through renaming
  139. module process2 = process1 [ s1=s2,p1=p2,v1=v2,u1=u2,v2=v3 ] endmodule
  140. module process3 = process1 [ s1=s3,p1=p3,v1=v3,u1=u3,v2=v4 ] endmodule
  141. module process4 = process1 [ s1=s4,p1=p4,v1=v4,u1=u4,v2=v5 ] endmodule
  142. module process5 = process1 [ s1=s5,p1=p5,v1=v5,u1=u5,v2=v1 ] endmodule
  143. // expected number of rounds
  144. rewards "num_rounds"
  145. [pick] true : 1;
  146. endrewards
  147. // labels
  148. label "elected" = s1=3&s2=3&s3=3&s4=3&s5=3;
  149. >>>>>>> 90d2b218a044edca8062084ee89d171695149c1e