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.

98 lines
3.7 KiB

  1. // asynchronous leader election
  2. // 4 processes
  3. // gxn/dxp 29/01/01
  4. mdp
  5. const int N= 5; // number of processes
  6. //----------------------------------------------------------------------------------------------------------------------------
  7. module process1
  8. // COUNTER
  9. c1 : [0..5-1];
  10. // STATES
  11. s1 : [0..4];
  12. // 0 make choice
  13. // 1 have not received neighbours choice
  14. // 2 active
  15. // 3 inactive
  16. // 4 leader
  17. // PREFERENCE
  18. p1 : [0..1];
  19. // VARIABLES FOR SENDING AND RECEIVING
  20. receive1 : [0..2];
  21. // not received anything
  22. // received choice
  23. // received counter
  24. sent1 : [0..2];
  25. // not send anything
  26. // sent choice
  27. // sent counter
  28. // pick value
  29. [] (s1=0) -> 0.5 : (s1'=1) & (p1'=0) + 0.5 : (s1'=1) & (p1'=1);
  30. // send preference
  31. [p12] (s1=1) & (sent1=0) -> (sent1'=1);
  32. // receive preference
  33. // stay active
  34. [p51] (s1=1) & (receive1=0) & !( (p1=0) & (p5=1) ) -> (s1'=2) & (receive1'=1);
  35. // become inactive
  36. [p51] (s1=1) & (receive1=0) & (p1=0) & (p5=1) -> (s1'=3) & (receive1'=1);
  37. // send preference (can now reset preference)
  38. [p12] (s1=2) & (sent1=0) -> (sent1'=1) & (p1'=0);
  39. // send counter (already sent preference)
  40. // not received counter yet
  41. [c12] (s1=2) & (sent1=1) & (receive1=1) -> (sent1'=2);
  42. // received counter (pick again)
  43. [c12] (s1=2) & (sent1=1) & (receive1=2) -> (s1'=0) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  44. // receive counter and not sent yet (note in this case do not pass it on as will send own counter)
  45. [c51] (s1=2) & (receive1=1) & (sent1<2) -> (receive1'=2);
  46. // receive counter and sent counter
  47. // only active process (decide)
  48. [c51] (s1=2) & (receive1=1) & (sent1=2) & (c5=N-1) -> (s1'=4) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  49. // other active process (pick again)
  50. [c51] (s1=2) & (receive1=1) & (sent1=2) & (c5<N-1) -> (s1'=0) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  51. // send preference (must have received preference) and can now reset
  52. [p12] (s1=3) & (receive1>0) & (sent1=0) -> (sent1'=1) & (p1'=0);
  53. // send counter (must have received counter first) and can now reset
  54. [c12] (s1=3) & (receive1=2) & (sent1=1) -> (s1'=3) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  55. // receive preference
  56. [p51] (s1=3) & (receive1=0) -> (p1'=p5) & (receive1'=1);
  57. // receive counter
  58. [c51] (s1=3) & (receive1=1) & (c5<N-1) -> (c1'=c5+1) & (receive1'=2);
  59. // done
  60. [done] (s1=4) -> (s1'=s1);
  61. // add loop for processes who are inactive
  62. [done] (s1=3) -> (s1'=s1);
  63. endmodule
  64. //----------------------------------------------------------------------------------------------------------------------------
  65. // construct further stations through renaming
  66. 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
  67. 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
  68. 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
  69. 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
  70. //----------------------------------------------------------------------------------------------------------------------------
  71. // reward - expected number of rounds (equals the number of times a process receives a counter)
  72. rewards
  73. [c12] true : 1;
  74. endrewards
  75. //----------------------------------------------------------------------------------------------------------------------------
  76. formula leaders = (s1=4?1:0)+(s2=4?1:0)+(s3=4?1:0)+(s4=4?1:0)+(s5=4?1:0);
  77. label "elected" = s1=4|s2=4|s3=4|s4=4|s5=4;