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.

61 lines
1.6 KiB

  1. //Randomised Consensus Protocol
  2. mdp
  3. const double p1; // in [0.2 , 0.8]
  4. const double p2; // in [0.2 , 0.8]
  5. const double p3; // in [0.2 , 0.8]
  6. const double p4; // in [0.2 , 0.8]
  7. const int N=4;
  8. const int K=16;
  9. const int range = 2*(K+1)*N;
  10. const int counter_init = (K+1)*N;
  11. const int left = N;
  12. const int right = 2*(K+1)*N - N;
  13. // shared coin
  14. global counter : [0..range] init counter_init;
  15. module process1
  16. // program counter
  17. pc1 : [0..3];
  18. // 0 - flip
  19. // 1 - write
  20. // 2 - check
  21. // 3 - finished
  22. // local coin
  23. coin1 : [0..1];
  24. // flip coin
  25. [] (pc1=0) -> p1 : (coin1'=0) & (pc1'=1) + 1 - p1 : (coin1'=1) & (pc1'=1);
  26. // write tails -1 (reset coin to add regularity)
  27. [] (pc1=1) & (coin1=0) & (counter>0) -> (counter'=counter-1) & (pc1'=2) & (coin1'=0);
  28. // write heads +1 (reset coin to add regularity)
  29. [] (pc1=1) & (coin1=1) & (counter<range) -> (counter'=counter+1) & (pc1'=2) & (coin1'=0);
  30. // check
  31. // decide tails
  32. [] (pc1=2) & (counter<=left) -> (pc1'=3) & (coin1'=0);
  33. // decide heads
  34. [] (pc1=2) & (counter>=right) -> (pc1'=3) & (coin1'=1);
  35. // flip again
  36. [] (pc1=2) & (counter>left) & (counter<right) -> (pc1'=0);
  37. // loop (all loop together when done)
  38. [done] (pc1=3) -> (pc1'=3);
  39. endmodule
  40. module process2 = process1[pc1=pc2,coin1=coin2,p1=p2] endmodule
  41. module process3 = process1[pc1=pc3,coin1=coin3,p1=p3] endmodule
  42. module process4 = process1[pc1=pc4,coin1=coin4,p1=p4] endmodule
  43. label "finished" = pc1=3 &pc2=3 &pc3=3 &pc4=3;
  44. label "all_coins_equal_1" = coin1=1 &coin2=1 &coin3=1 &coin4=1 ;
  45. rewards "steps"
  46. true : 1;
  47. endrewards