Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. // Murder-in-the-family.als
  2. // Marcin Szlenk 2020
  3.  
  4. // 1. Launch the Alloy Analyzer.
  5. // 2. Select the Open icon and load this file.
  6. // 3. Select the Execute icon to run the 'run' command.
  7. // 4. Select the Show icon to show an instance of the model. Examine the diagram.
  8. // 5. Select the Next icon to ask for another instance.
  9.  
  10. // Complete the model (only the lines with 'TO DO') and solve the below puzzle
  11. // (from Summers 1968):
  12.  
  13. // Murder occurred one evening in the home of a married couple
  14. // and their son and daughter. One member of the family murdered
  15. // another member, the third member witnessed the crime, and the
  16. // fourth member was an accessory after the fact.
  17. //
  18. // 1. The accessory and the witness were of opposite sex.
  19. // 2. The oldest member and the witness were of opposite sex.
  20. // 3. The youngest member and the victim were of opposite sex.
  21. // 4. The accessory was older than the victim.
  22. // 5. The father was the oldest member.
  23. // 6. The killer was not the youngest member.
  24. //
  25. // Which one of the four father, mother, son, or daughter was the killer?
  26.  
  27. // to witness the crime — być świadkiem przestępstwa;
  28. // accessory — współsprawca (pomagający, ale nie uczestniczący w przestępstwie).
  29.  
  30. abstract sig Sex {}
  31. one sig Woman, Man extends Sex {}
  32.  
  33. abstract sig Role {}
  34. one sig Killer, Victim, Witness, Accessory extends Role {}
  35.  
  36. abstract sig Person {
  37. sex: one Sex,
  38. role: one Role,
  39. olderThan: set Person
  40. }
  41.  
  42. one sig Father, Mother, Son, Daughter extends Person {}
  43.  
  44. fact {
  45. //each person plays a different role
  46. all r: Role | one role.r
  47. //'olderThan' has no cycles
  48. no p: Person | p in p.^olderThan
  49. //'olderThan' is transitive
  50. all p1, p2, p3: Person |
  51. p1->p2 in olderThan and p2->p3 in olderThan =>
  52. p1->p3 in olderThan
  53. }
  54.  
  55. pred Oldest[p: Person] {
  56. no olderThan.p
  57. }
  58.  
  59. pred Youngest[p: Person] {
  60. no p.olderThan
  61. }
  62.  
  63. fact WhatWeKnow {
  64. // The parents are older than their children
  65. (Father + Mother) -> (Son + Daughter) in olderThan
  66.  
  67. // The father and the son are men, while
  68. // the mother and the daughter are women
  69.  
  70. Father.sex = Man // TO DO
  71. Son.sex = Man
  72. Daughter.sex = Woman
  73. Mother.sex = Woman
  74.  
  75. // 1. The accessory and the witness were of opposite sex.
  76. all p1, p2: Person | p1.role = Accessory and p2.role = Witness => p1.sex != p2.sex
  77.  
  78. // 2. The oldest member and the witness were of opposite sex.
  79.  
  80. all p1: Person | Oldest[p1] => p1.role != Witness
  81. all disj p1, p2: Person | Oldest[p1] and p2.role = Witness => p1.sex != p2.sex
  82.  
  83. // 3. The youngest member and the victim were of opposite sex.
  84.  
  85. all p1: Person | Youngest[p1] => p1.role != Victim
  86. all disj p1, p2: Person | Youngest[p1] and p2.role = Victim => p1.sex != p2.sex
  87.  
  88. // 4. The accessory was older than the victim.
  89.  
  90. all disj p1, p2: Person | p1.role = Accessory and p2.role = Victim => p2 in p1.olderThan
  91.  
  92. // 5. The father was the oldest member.
  93.  
  94. Father.olderThan = Mother + Daughter + Son
  95.  
  96. // 6. The killer was not the youngest member.
  97.  
  98. all p1: Person | p1.role = Killer => not Youngest[p1]
  99.  
  100. }
  101.  
  102. run {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement