Guest User

Untitled

a guest
Jun 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1.  
  2. open util/ordering[Date]
  3.  
  4. sig Date {}
  5. sig Price {}
  6. sig Client {}
  7. sig Service {}
  8. sig Package {
  9. services: set Service -> lone Price,
  10. incompatibles: set Package
  11. }
  12.  
  13. sig Subscription {
  14. package: one Package,
  15. start: one Date,
  16. end: one Date
  17. }
  18.  
  19. sig Operator {
  20. clients: set Client,
  21. packages: set Package,
  22. subscriptions: clients -> Subscription
  23. }
  24.  
  25. fun IncompatibleSubscriptions[] : Subscription->Subscription {
  26. { disj x, y:Subscription | lt[x.start, y.end] and lt[y.start, x.end] and x.package -> y.package in incompatibles }
  27. }
  28.  
  29. /*
  30. // A relação de incompatibilidade tem de ser simétrica e tem de conter elementos da identidade
  31. fact {
  32. incompatibles = ~incompatibles
  33. all p:Package | p in p.incompatibles
  34. }
  35.  
  36. // O cliente não pode ter pacotes incompatíveis
  37. fact {
  38. all o:Operator |
  39. no (((~(o.subscriptions) . (o.subscriptions)) - iden) & { x, y:Subscription | lt[x.start, y.end] and lt[y.start, x.end] and x.package -> y.package in incompatibles } )
  40. }
  41.  
  42. // Se dois pacotes contiverem o mesmo serviço, são incompatíveis
  43. fact { services.Price.~(services.Price) - iden in incompatibles }
  44.  
  45. // Um pacote tem de ter pelo menos um serviço
  46. fact { services.Price.Service = Package }
  47.  
  48. // A data inicial tem de ser anterior à data final
  49. fact { (~start).end in ^next }
  50.  
  51. // Um cliente só pode estar subscrito a um pacote que esteja no operador
  52. fact { all o:Operator | Client.(o.subscriptions).package in o.packages }
  53.  
  54. fact { some subscriptions }*/
  55.  
  56. pred inv[o:Operator] {
  57. incompatibles = ~incompatibles
  58. all p:Package | p in p.incompatibles
  59. services.Price.~(services.Price) - iden in incompatibles
  60. services.Price.Service = Package
  61. (~start).end in ^next
  62.  
  63. no (((~(o.subscriptions) . (o.subscriptions)) - iden) & IncompatibleSubscriptions[] )
  64. Client.(o.subscriptions).package in o.packages
  65. }
  66.  
  67. pred create_client[o,o':Operator, c:Client] {
  68. // pre-conditions
  69. c not in o.clients
  70.  
  71. // frame-conditions
  72. o'.clients = o.clients + c
  73. o'.packages = o.packages
  74. o.subscriptions = o'.subscriptions
  75. }
  76.  
  77. pred delete_client[o,o':Operator, c:Client] {
  78. // pre-conditions
  79. c in o.clients
  80. no c.(o.subscriptions)
  81.  
  82. // frame-conditions
  83. o'.clients = o.clients - c
  84. o'.packages = o.packages
  85. o'.subscriptions = o.subscriptions
  86. }
  87.  
  88. pred create_package[o,o':Operator, p:Package] {
  89. // pre-conditions
  90. p not in o.packages
  91.  
  92. // frame-conditions
  93. o'.clients = o.clients
  94. o'.subscriptions = o.subscriptions
  95. o'.packages = o.packages + p
  96. }
  97.  
  98. pred delete_package[o,o': Operator, p:Package] {
  99. // pre-conditions
  100. p in o.packages
  101. p not in Client.(o.subscriptions).package
  102.  
  103. // frame-conditions
  104. o'.clients = o.clients
  105. o'.subscriptions = o.subscriptions
  106. o'.packages = o.packages - p
  107. }
  108.  
  109. pred create_client_package[o,o':Operator, c:Client, s:Subscription] {
  110. // pre-conditions
  111. c in o.clients
  112. s.package in o.packages
  113. c->s not in o.subscriptions
  114. no (s -> c.(o.subscriptions)) & IncompatibleSubscriptions[]
  115.  
  116. // frame-conditions
  117. o'.clients = o.clients
  118. o'.packages = o.packages
  119. o'.subscriptions = o.subscriptions + c->s
  120. }
  121.  
  122. pred change_subscription_end_date[o,o':Operator, c:Client, s, s':Subscription] {
  123. // pre conditions
  124. c in o.clients
  125. c->s in o.subscriptions
  126.  
  127. s.package = s'.package
  128. s.start = s'.start
  129. no (s' -> (c.(o.subscriptions) - s)) & IncompatibleSubscriptions[]
  130.  
  131. // frame conditions
  132. o'.clients = o.clients
  133. o'.packages = o.packages
  134. o'.subscriptions = o.subscriptions - (c->s) + (c->s')
  135. }
  136.  
  137. pred create_client_consistent[o,o':Operator, c:Client] { inv[o] && create_client[o,o',c] }
  138. assert create_client_safe { all o,o':Operator, c:Client | inv[o] && create_client[o,o',c] => inv[o'] }
  139.  
  140. pred delete_client_consistent[o,o':Operator, c:Client] { inv[o] && delete_client[o,o',c] }
  141. assert delete_client_safe { all o,o':Operator, c:Client | inv[o] && delete_client[o,o',c] => inv[o'] }
  142.  
  143. pred create_package_consistent[o,o':Operator, p:Package] { inv[o] && create_package[o,o',p] }
  144. assert create_package_safe { all o,o':Operator, p:Package | inv[o] && create_package[o,o',p] => inv[o'] }
  145.  
  146. pred delete_package_consistent[o,o':Operator, p:Package] { inv[o] && delete_package[o,o',p] }
  147. assert delete_package_safe { all o,o':Operator, p:Package | inv[o] && delete_package[o,o',p] => inv[o'] }
  148.  
  149. pred create_client_package_consistent[o,o':Operator, c:Client, s:Subscription] { inv[o] && create_client_package[o,o',c,s] }
  150. assert create_client_package_safe { all o,o':Operator, c:Client, s:Subscription | inv[o] && create_client_package[o,o',c,s] => inv[o'] }
  151.  
  152. pred change_subscription_end_date_consistent[o,o':Operator, c:Client, s, s':Subscription] { inv[o] && change_subscription_end_date[o,o',c,s,s'] }
  153. assert change_subscription_end_date_safe { all o,o':Operator, c:Client, s, s':Subscription | inv[o] && change_subscription_end_date[o,o',c,s,s'] => inv[o'] }
  154.  
  155. check create_client_safe for 5
  156. check delete_client_safe for 5
  157. check create_package_safe for 5
  158. check delete_package_safe for 5
  159. check create_client_package_safe for 5
  160. check change_subscription_end_date_safe for 5
  161.  
  162. run create_client_consistent for 5
  163. run delete_client_consistent for 5
  164. run create_package_consistent for 5
  165. run delete_package_consistent for 5
  166. run create_client_package_consistent for 5
  167. run change_subscription_end_date_consistent for 5
Add Comment
Please, Sign In to add comment