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.

199 lines
7.3 KiB

  1. <<<<<<< HEAD
  2. // asynchronous leader election
  3. // 4 processes
  4. // gxn/dxp 29/01/01
  5. mdp
  6. const int N= 5; // number of processes
  7. //----------------------------------------------------------------------------------------------------------------------------
  8. module process1
  9. // COUNTER
  10. c1 : [0..5-1];
  11. // STATES
  12. s1 : [0..4];
  13. // 0 make choice
  14. // 1 have not received neighbours choice
  15. // 2 active
  16. // 3 inactive
  17. // 4 leader
  18. // PREFERENCE
  19. p1 : [0..1];
  20. // VARIABLES FOR SENDING AND RECEIVING
  21. receive1 : [0..2];
  22. // not received anything
  23. // received choice
  24. // received counter
  25. sent1 : [0..2];
  26. // not send anything
  27. // sent choice
  28. // sent counter
  29. // pick value
  30. [] (s1=0) -> 0.5 : (s1'=1) & (p1'=0) + 0.5 : (s1'=1) & (p1'=1);
  31. // send preference
  32. [p12] (s1=1) & (sent1=0) -> (sent1'=1);
  33. // receive preference
  34. // stay active
  35. [p51] (s1=1) & (receive1=0) & !( (p1=0) & (p5=1) ) -> (s1'=2) & (receive1'=1);
  36. // become inactive
  37. [p51] (s1=1) & (receive1=0) & (p1=0) & (p5=1) -> (s1'=3) & (receive1'=1);
  38. // send preference (can now reset preference)
  39. [p12] (s1=2) & (sent1=0) -> (sent1'=1) & (p1'=0);
  40. // send counter (already sent preference)
  41. // not received counter yet
  42. [c12] (s1=2) & (sent1=1) & (receive1=1) -> (sent1'=2);
  43. // received counter (pick again)
  44. [c12] (s1=2) & (sent1=1) & (receive1=2) -> (s1'=0) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  45. // receive counter and not sent yet (note in this case do not pass it on as will send own counter)
  46. [c51] (s1=2) & (receive1=1) & (sent1<2) -> (receive1'=2);
  47. // receive counter and sent counter
  48. // only active process (decide)
  49. [c51] (s1=2) & (receive1=1) & (sent1=2) & (c5=N-1) -> (s1'=4) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  50. // other active process (pick again)
  51. [c51] (s1=2) & (receive1=1) & (sent1=2) & (c5<N-1) -> (s1'=0) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  52. // send preference (must have received preference) and can now reset
  53. [p12] (s1=3) & (receive1>0) & (sent1=0) -> (sent1'=1) & (p1'=0);
  54. // send counter (must have received counter first) and can now reset
  55. [c12] (s1=3) & (receive1=2) & (sent1=1) -> (s1'=3) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  56. // receive preference
  57. [p51] (s1=3) & (receive1=0) -> (p1'=p5) & (receive1'=1);
  58. // receive counter
  59. [c51] (s1=3) & (receive1=1) & (c5<N-1) -> (c1'=c5+1) & (receive1'=2);
  60. // done
  61. [done] (s1=4) -> (s1'=s1);
  62. // add loop for processes who are inactive
  63. [done] (s1=3) -> (s1'=s1);
  64. endmodule
  65. //----------------------------------------------------------------------------------------------------------------------------
  66. // construct further stations through renaming
  67. module process2=process1[s1=s2,p1=p2,c1=c2,sent1=sent2,receive1=receive2,p12=p23,p51=p12,c12=c23,c51=c12,p5=p1,c5=c1] endmodule
  68. module process3=process1[s1=s3,p1=p3,c1=c3,sent1=sent3,receive1=receive3,p12=p34,p51=p23,c12=c34,c51=c23,p5=p2,c5=c2] endmodule
  69. module process4=process1[s1=s4,p1=p4,c1=c4,sent1=sent4,receive1=receive4,p12=p45,p51=p34,c12=c45,c51=c34,p5=p3,c5=c3] endmodule
  70. module process5=process1[s1=s5,p1=p5,c1=c5,sent1=sent5,receive1=receive5,p12=p51,p51=p45,c12=c51,c51=c45,p5=p4,c5=c4] endmodule
  71. //----------------------------------------------------------------------------------------------------------------------------
  72. // reward - expected number of rounds (equals the number of times a process receives a counter)
  73. rewards "rounds"
  74. [c12] true : 1;
  75. endrewards
  76. //----------------------------------------------------------------------------------------------------------------------------
  77. formula leaders = (s1=4?1:0)+(s2=4?1:0)+(s3=4?1:0)+(s4=4?1:0)+(s5=4?1:0);
  78. label "elected" = s1=4|s2=4|s3=4|s4=4|s5=4;
  79. =======
  80. // asynchronous leader election
  81. // 4 processes
  82. // gxn/dxp 29/01/01
  83. mdp
  84. const int N= 5; // number of processes
  85. //----------------------------------------------------------------------------------------------------------------------------
  86. module process1
  87. // COUNTER
  88. c1 : [0..5-1];
  89. // STATES
  90. s1 : [0..4];
  91. // 0 make choice
  92. // 1 have not received neighbours choice
  93. // 2 active
  94. // 3 inactive
  95. // 4 leader
  96. // PREFERENCE
  97. p1 : [0..1];
  98. // VARIABLES FOR SENDING AND RECEIVING
  99. receive1 : [0..2];
  100. // not received anything
  101. // received choice
  102. // received counter
  103. sent1 : [0..2];
  104. // not send anything
  105. // sent choice
  106. // sent counter
  107. // pick value
  108. [] (s1=0) -> 0.5 : (s1'=1) & (p1'=0) + 0.5 : (s1'=1) & (p1'=1);
  109. // send preference
  110. [p12] (s1=1) & (sent1=0) -> (sent1'=1);
  111. // receive preference
  112. // stay active
  113. [p51] (s1=1) & (receive1=0) & !( (p1=0) & (p5=1) ) -> (s1'=2) & (receive1'=1);
  114. // become inactive
  115. [p51] (s1=1) & (receive1=0) & (p1=0) & (p5=1) -> (s1'=3) & (receive1'=1);
  116. // send preference (can now reset preference)
  117. [p12] (s1=2) & (sent1=0) -> (sent1'=1) & (p1'=0);
  118. // send counter (already sent preference)
  119. // not received counter yet
  120. [c12] (s1=2) & (sent1=1) & (receive1=1) -> (sent1'=2);
  121. // received counter (pick again)
  122. [c12] (s1=2) & (sent1=1) & (receive1=2) -> (s1'=0) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  123. // receive counter and not sent yet (note in this case do not pass it on as will send own counter)
  124. [c51] (s1=2) & (receive1=1) & (sent1<2) -> (receive1'=2);
  125. // receive counter and sent counter
  126. // only active process (decide)
  127. [c51] (s1=2) & (receive1=1) & (sent1=2) & (c5=N-1) -> (s1'=4) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  128. // other active process (pick again)
  129. [c51] (s1=2) & (receive1=1) & (sent1=2) & (c5<N-1) -> (s1'=0) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  130. // send preference (must have received preference) and can now reset
  131. [p12] (s1=3) & (receive1>0) & (sent1=0) -> (sent1'=1) & (p1'=0);
  132. // send counter (must have received counter first) and can now reset
  133. [c12] (s1=3) & (receive1=2) & (sent1=1) -> (s1'=3) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  134. // receive preference
  135. [p51] (s1=3) & (receive1=0) -> (p1'=p5) & (receive1'=1);
  136. // receive counter
  137. [c51] (s1=3) & (receive1=1) & (c5<N-1) -> (c1'=c5+1) & (receive1'=2);
  138. // done
  139. [done] (s1=4) -> (s1'=s1);
  140. // add loop for processes who are inactive
  141. [done] (s1=3) -> (s1'=s1);
  142. endmodule
  143. //----------------------------------------------------------------------------------------------------------------------------
  144. // construct further stations through renaming
  145. module process2=process1[s1=s2,p1=p2,c1=c2,sent1=sent2,receive1=receive2,p12=p23,p51=p12,c12=c23,c51=c12,p5=p1,c5=c1] endmodule
  146. module process3=process1[s1=s3,p1=p3,c1=c3,sent1=sent3,receive1=receive3,p12=p34,p51=p23,c12=c34,c51=c23,p5=p2,c5=c2] endmodule
  147. module process4=process1[s1=s4,p1=p4,c1=c4,sent1=sent4,receive1=receive4,p12=p45,p51=p34,c12=c45,c51=c34,p5=p3,c5=c3] endmodule
  148. module process5=process1[s1=s5,p1=p5,c1=c5,sent1=sent5,receive1=receive5,p12=p51,p51=p45,c12=c51,c51=c45,p5=p4,c5=c4] endmodule
  149. //----------------------------------------------------------------------------------------------------------------------------
  150. // reward - expected number of rounds (equals the number of times a process receives a counter)
  151. rewards "rounds"
  152. [c12] true : 1;
  153. endrewards
  154. //----------------------------------------------------------------------------------------------------------------------------
  155. formula leaders = (s1=4?1:0)+(s2=4?1:0)+(s3=4?1:0)+(s4=4?1:0)+(s5=4?1:0);
  156. label "elected" = s1=4|s2=4|s3=4|s4=4|s5=4;
  157. >>>>>>> 90d2b218a044edca8062084ee89d171695149c1e