ex3.b.smv 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. MODULE passenger(on_boat)
  2. VAR
  3. crossed : boolean;
  4. ASSIGN
  5. init(crossed) := FALSE;
  6. next(crossed) := on_boat ? !crossed : crossed;
  7. MODULE main
  8. VAR
  9. selected_passenger_1 : {h1, w1, h2, w2, h3, w3};
  10. selected_passenger_2 : {h1, w1, h2, w2, h3, w3, none};
  11. boat_crossed : boolean;
  12. husband1 : passenger(
  13. h1 in {selected_passenger_1, selected_passenger_2}
  14. );
  15. wife1 : passenger(
  16. w1 in {selected_passenger_1, selected_passenger_2}
  17. );
  18. husband2 : passenger(
  19. h2 in {selected_passenger_1, selected_passenger_2}
  20. );
  21. wife2 : passenger(
  22. w2 in {selected_passenger_1, selected_passenger_2}
  23. );
  24. husband3 : passenger(
  25. h3 in {selected_passenger_1, selected_passenger_2}
  26. );
  27. wife3 : passenger(
  28. w3 in {selected_passenger_1, selected_passenger_2}
  29. );
  30. ASSIGN
  31. init(boat_crossed) := FALSE;
  32. next(boat_crossed) := !boat_crossed;
  33. -- the next state logic of selected passenger 1 is simple, namely exactly as it was in task (a)
  34. next(selected_passenger_1) := {
  35. next(boat_crossed) = husband1.crossed ? h1 : selected_passenger_1,
  36. next(boat_crossed) = wife1.crossed ? w1 : selected_passenger_1,
  37. next(boat_crossed) = husband2.crossed ? h2 : selected_passenger_1,
  38. next(boat_crossed) = wife2.crossed ? w2 : selected_passenger_1,
  39. next(boat_crossed) = husband3.crossed ? h3 : selected_passenger_1,
  40. next(boat_crossed) = wife3.crossed ? w3 : selected_passenger_1
  41. };
  42. -- this time, we prevent initialization of both passengers to the same person
  43. init(selected_passenger_2) := {
  44. selected_passenger_1 != h1 ? h1 : none,
  45. selected_passenger_1 != w1 ? w1 : none,
  46. selected_passenger_1 != h2 ? h2 : none,
  47. selected_passenger_1 != w2 ? w2 : none,
  48. selected_passenger_1 != h3 ? h3 : none,
  49. selected_passenger_1 != w3 ? w3 : none
  50. };
  51. -- the next state of passenger 2 then depends on passenger 1
  52. -- to make unique choices for each selection, we additionally require that a passenger has not already been selected as selected passenger 1
  53. -- finally, because we need to allow the crossing of just one passenger, there is an additional none state
  54. next(selected_passenger_2) := {
  55. next(boat_crossed) = husband1.crossed & next(selected_passenger_1) != h1 ? h1 : selected_passenger_2,
  56. next(boat_crossed) = wife1.crossed & next(selected_passenger_1) != w1 ? w1 : selected_passenger_2,
  57. next(boat_crossed) = husband2.crossed & next(selected_passenger_1) != h2 ? h2 : selected_passenger_2,
  58. next(boat_crossed) = wife2.crossed & next(selected_passenger_1) != w2 ? w2 : selected_passenger_2,
  59. next(boat_crossed) = husband3.crossed & next(selected_passenger_1) != h3 ? h3 : selected_passenger_2,
  60. next(boat_crossed) = wife3.crossed & next(selected_passenger_1) != w3 ? w3 : selected_passenger_2,
  61. none
  62. };
  63. DEFINE
  64. -- the definition of the jealousness property is not too complicated, it first checks for unequivalence of the husband 1 and the wife 1, and then enumerates all equivalences of pairings of wife 1 with the other husbands
  65. -- equivalence in this case refers to the state where the crossing of a person is the same as that of another person
  66. -- so in essence we check whether the crossing value of husband 1 and wife 1 are not the same, but the crossing value of wife1 with any of the other husbands 2 or 3 is
  67. is_jealous_h1 := (
  68. husband1.crossed != wife1.crossed & (
  69. wife1.crossed = husband2.crossed |
  70. wife1.crossed = husband3.crossed
  71. ));
  72. -- this is the same as in the above explanation, but the roles of 1 and 2 are flipped
  73. is_jealous_h2 := (
  74. husband2.crossed != wife2.crossed & (
  75. wife2.crossed = husband1.crossed |
  76. wife2.crossed = husband3.crossed
  77. ));
  78. -- this is the same as in the above explanation, but the roles of 1 and 3 are flipped
  79. is_jealous_h3 := (
  80. husband3.crossed != wife3.crossed & (
  81. wife3.crossed = husband1.crossed |
  82. wife3.crossed = husband2.crossed
  83. ));
  84. -- all passengers have been crossed successfully if their crossings all evaluate to true
  85. all_crossed := (
  86. husband1.crossed & wife1.crossed &
  87. husband2.crossed & wife2.crossed &
  88. husband3.crossed & wife3.crossed);
  89. LTLSPEC ! (
  90. G !(is_jealous_h1 | is_jealous_h2 | is_jealous_h3) &
  91. F all_crossed
  92. );