The source code and dockerfile for the GSW2024 AI Lab.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

88 lines
2.9 KiB

2 months ago
  1. // asynchronous leader election
  2. // 4 processes
  3. // gxn/dxp 29/01/01
  4. mdp
  5. const int N = 4; // number of processes
  6. module process1
  7. // COUNTER
  8. c1 : [0..N-1];
  9. // STATES
  10. s1 : [0..4];
  11. // 0 make choice
  12. // 1 have not received neighbours choice
  13. // 2 active
  14. // 3 inactive
  15. // 4 leader
  16. // PREFERENCE
  17. p1 : [0..1];
  18. // VARIABLES FOR SENDING AND RECEIVING
  19. receive1 : [0..2];
  20. // not received anything
  21. // received choice
  22. // received counter
  23. sent1 : [0..2];
  24. // not send anything
  25. // sent choice
  26. // sent counter
  27. // pick value
  28. [] (s1=0) -> 0.5 : (s1'=1) & (p1'=0) + 0.5 : (s1'=1) & (p1'=1);
  29. // send preference
  30. [p12] (s1=1) & (sent1=0) -> (sent1'=1);
  31. // receive preference
  32. // stay active
  33. [p41] (s1=1) & (receive1=0) & !( (p1=0) & (p4=1) ) -> (s1'=2) & (receive1'=1);
  34. // become inactive
  35. [p41] (s1=1) & (receive1=0) & (p1=0) & (p4=1) -> (s1'=3) & (receive1'=1);
  36. // send preference (can now reset preference)
  37. [p12] (s1=2) & (sent1=0) -> (sent1'=1) & (p1'=0);
  38. // send counter (already sent preference)
  39. // not received counter yet
  40. [c12] (s1=2) & (sent1=1) & (receive1=1) -> (sent1'=2);
  41. // received counter (pick again)
  42. [c12] (s1=2) & (sent1=1) & (receive1=2) -> (s1'=0) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  43. // receive counter and not sent yet (note in this case do not pass it on as will send own counter)
  44. [c41] (s1=2) & (receive1=1) & (sent1<2) -> (receive1'=2);
  45. // receive counter and sent counter
  46. // only active process (decide)
  47. [c41] (s1=2) & (receive1=1) & (sent1=2) & (c4=N-1) -> (s1'=4) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  48. // other active process (pick again)
  49. [c41] (s1=2) & (receive1=1) & (sent1=2) & (c4<N-1) -> (s1'=0) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  50. // send preference (must have received preference) and can now reset
  51. [p12] (s1=3) & (receive1>0) & (sent1=0) -> (sent1'=1) & (p1'=0);
  52. // send counter (must have received counter first) and can now reset
  53. [c12] (s1=3) & (receive1=2) & (sent1=1) -> (s1'=3) & (p1'=0) & (c1'=0) & (sent1'=0) & (receive1'=0);
  54. // receive preference
  55. [p41] (s1=3) & (receive1=0) -> (p1'=p4) & (receive1'=1);
  56. // receive counter
  57. [c41] (s1=3) & (receive1=1) & (c4<N-1) -> (c1'=c4+1) & (receive1'=2);
  58. // done
  59. [done] (s1=4) -> (s1'=s1);
  60. // add loop for processes who are inactive
  61. [done] (s1=3) -> (s1'=s1);
  62. endmodule
  63. module process2=process1[s1=s2,p1=p2,c1=c2,sent1=sent2,receive1=receive2,p12=p23,p41=p12,c12=c23,c41=c12,p4=p1,c4=c1] endmodule
  64. module process3=process1[s1=s3,p1=p3,c1=c3,sent1=sent3,receive1=receive3,p12=p34,p41=p23,c12=c34,c41=c23,p4=p2,c4=c2] endmodule
  65. module process4=process1[s1=s4,p1=p4,c1=c4,sent1=sent4,receive1=receive4,p12=p41,p41=p34,c12=c41,c41=c34,p4=p3,c4=c3] endmodule
  66. // reward - expected number of rounds (equals the number of times a process receives a counter)
  67. rewards "rounds"
  68. [c12] true : 1;
  69. endrewards
  70. label "elected" = s1=4|s2=4|s3=4|s4=4;