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.

89 lines
2.6 KiB

  1. // synchronous leader election protocol (itai & Rodeh)
  2. // dxp/gxn 25/01/01
  3. dtmc
  4. // CONSTANTS
  5. const N = 4; // number of processes
  6. const 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 -> (c'=c);
  18. // pick again reset counter
  19. [retry] !(u1|u2|u3|u4) -> (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=v1 ] endmodule
  67. // expected number of rounds
  68. rewards "num_rounds"
  69. [pick] true : 1;
  70. endrewards
  71. // labels
  72. label "elected" = s1=3&s2=3&s3=3&s4=3;