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.

157 lines
4.3 KiB

  1. // Modest version of http://www.prismmodelchecker.org/casestudies/consensus_prism.php
  2. // Command line: mcsta.exe consensus-6.modest -S Memory --nochainopt --bounded-alg StateElimination -E "K=2"
  3. action done;
  4. // constants
  5. const int N = 6;
  6. const int K = 4;
  7. const int range = 2 * (K + 1) * N;
  8. const int counter_init = (K + 1) * N;
  9. const int left = N;
  10. const int right = 2 * (K + 1) * N - N;
  11. // shared coin
  12. int(0..range) counter = counter_init;
  13. reward coin_flips;
  14. property C1 = P(<> (fin1 == 1 && fin2 == 1 && fin3 == 1 && fin4 == 1 && fin5 == 1 && fin6 == 1)) >= 1;
  15. property C2 = Pmin(<> (fin1 == 1 && fin2 == 1 && fin3 == 1 && fin4 == 1 && fin5 == 1 && fin6 == 1 && coin1 == 1 && coin2 == 1 && coin3 == 1 && coin4 == 1 && coin5 == 1 && coin6 == 1));
  16. int(0..1) fin1, fin2, fin3, fin4, fin5, fin6;
  17. int(0..1) coin1, coin2, coin3, coin4, coin5, coin6;
  18. process Tourist1()
  19. {
  20. process Flip() { palt { :1: {= coin1 = 0, coin_flips++ =} :1: {= coin1 = 1, coin_flips++ =} }; Write() }
  21. process Write() {
  22. alt {
  23. :: when(coin1 == 0 && counter > 0) {= counter-- =}; Check()
  24. :: when(coin1 == 1 && counter < range) {= counter++, coin1 = 0 =}; Check()
  25. }
  26. }
  27. process Check() {
  28. alt {
  29. :: when(counter <= left) {= coin1 = 0, fin1 = 1 =}; Finished()
  30. :: when(counter >= right) {= coin1 = 1, fin1 = 1 =}; Finished()
  31. :: when(counter > left && counter < right) Tourist1()
  32. }
  33. }
  34. process Finished() { done; Finished() }
  35. Flip()
  36. }
  37. process Tourist2()
  38. {
  39. process Flip() { palt { :1: {= coin2 = 0, coin_flips++ =} :1: {= coin2 = 1, coin_flips++ =} }; Write() }
  40. process Write() {
  41. alt {
  42. :: when(coin2 == 0 && counter > 0) {= counter-- =}; Check()
  43. :: when(coin2 == 1 && counter < range) {= counter++, coin2 = 0 =}; Check()
  44. }
  45. }
  46. process Check() {
  47. alt {
  48. :: when(counter <= left) {= coin2 = 0, fin2 = 1 =}; Finished()
  49. :: when(counter >= right) {= coin2 = 1, fin2 = 1 =}; Finished()
  50. :: when(counter > left && counter < right) Tourist2()
  51. }
  52. }
  53. process Finished() { done; Finished() }
  54. Flip()
  55. }
  56. process Tourist3()
  57. {
  58. process Flip() { palt { :1: {= coin3 = 0, coin_flips++ =} :1: {= coin3 = 1, coin_flips++ =} }; Write() }
  59. process Write() {
  60. alt {
  61. :: when(coin3 == 0 && counter > 0) {= counter-- =}; Check()
  62. :: when(coin3 == 1 && counter < range) {= counter++, coin3 = 0 =}; Check()
  63. }
  64. }
  65. process Check() {
  66. alt {
  67. :: when(counter <= left) {= coin3 = 0, fin3 = 1 =}; Finished()
  68. :: when(counter >= right) {= coin3 = 1, fin3 = 1 =}; Finished()
  69. :: when(counter > left && counter < right) Tourist3()
  70. }
  71. }
  72. process Finished() { done; Finished() }
  73. Flip()
  74. }
  75. process Tourist4()
  76. {
  77. process Flip() { palt { :1: {= coin4 = 0, coin_flips++ =} :1: {= coin4 = 1, coin_flips++ =} }; Write() }
  78. process Write() {
  79. alt {
  80. :: when(coin4 == 0 && counter > 0) {= counter-- =}; Check()
  81. :: when(coin4 == 1 && counter < range) {= counter++, coin4 = 0 =}; Check()
  82. }
  83. }
  84. process Check() {
  85. alt {
  86. :: when(counter <= left) {= coin4 = 0, fin4 = 1 =}; Finished()
  87. :: when(counter >= right) {= coin4 = 1, fin4 = 1 =}; Finished()
  88. :: when(counter > left && counter < right) Tourist4()
  89. }
  90. }
  91. process Finished() { done; Finished() }
  92. Flip()
  93. }
  94. process Tourist5()
  95. {
  96. process Flip() { palt { :1: {= coin5 = 0, coin_flips++ =} :1: {= coin5 = 1, coin_flips++ =} }; Write() }
  97. process Write() {
  98. alt {
  99. :: when(coin5 == 0 && counter > 0) {= counter-- =}; Check()
  100. :: when(coin5 == 1 && counter < range) {= counter++, coin5 = 0 =}; Check()
  101. }
  102. }
  103. process Check() {
  104. alt {
  105. :: when(counter <= left) {= coin5 = 0, fin5 = 1 =}; Finished()
  106. :: when(counter >= right) {= coin5 = 1, fin5 = 1 =}; Finished()
  107. :: when(counter > left && counter < right) Tourist5()
  108. }
  109. }
  110. process Finished() { done; Finished() }
  111. Flip()
  112. }
  113. process Tourist6()
  114. {
  115. process Flip() { palt { :1: {= coin6 = 0, coin_flips++ =} :1: {= coin6 = 1, coin_flips++ =} }; Write() }
  116. process Write() {
  117. alt {
  118. :: when(coin6 == 0 && counter > 0) {= counter-- =}; Check()
  119. :: when(coin6 == 1 && counter < range) {= counter++, coin6 = 0 =}; Check()
  120. }
  121. }
  122. process Check() {
  123. alt {
  124. :: when(counter <= left) {= coin6 = 0, fin6 = 1 =}; Finished()
  125. :: when(counter >= right) {= coin6 = 1, fin6 = 1 =}; Finished()
  126. :: when(counter > left && counter < right) Tourist6()
  127. }
  128. }
  129. process Finished() { done; Finished() }
  130. Flip()
  131. }
  132. par {
  133. :: Tourist1()
  134. :: Tourist2()
  135. :: Tourist3()
  136. :: Tourist4()
  137. :: Tourist5()
  138. :: Tourist6()
  139. }