reachability_graph.mvc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. include "primitives.alh"
  2. include "object_operations.alh"
  3. include "modelling.alh"
  4. SimpleAttribute String {
  5. name = "String"
  6. }
  7. SimpleAttribute Natural {
  8. name = "Natural"
  9. }
  10. SimpleAttribute Boolean {
  11. name = "Boolean"
  12. }
  13. Class State {
  14. name = "State"
  15. name : String
  16. error : Boolean
  17. }
  18. Class InitialState : State {
  19. name = "InitialState"
  20. lower_cardinality = 1
  21. upper_cardinality = 1
  22. }
  23. Class Place {
  24. name = "Place"
  25. name : String
  26. tokens : Natural
  27. }
  28. Association Transition (State, State) {
  29. name = "Transition"
  30. name : String
  31. }
  32. Association Contains (State, Place) {
  33. name = "Contains"
  34. }
  35. GlobalConstraint {
  36. global_constraint = $
  37. String function constraint(model : Element):
  38. Element states
  39. Element places
  40. String state
  41. String place
  42. Element expected
  43. Element got
  44. states = allInstances(model, "State")
  45. if (set_len(states) > 0):
  46. expected = create_node()
  47. state = set_pop(states)
  48. places = allAssociationDestinations(model, state, "Contains")
  49. while (set_len(places)):
  50. place = set_pop(places)
  51. set_add(expected, read_attribute(model, place, "name"))
  52. else:
  53. return "OK"!
  54. while (set_len(states) > 0):
  55. got = create_node()
  56. state = set_pop(states)
  57. places = allAssociationDestinations(model, state, "Contains")
  58. while (set_len(places) > 0):
  59. place = set_pop(places)
  60. set_add(got, read_attribute(model, place, "name"))
  61. if (bool_not(set_equality(got, expected))):
  62. return "States don't all agree on the set of places"!
  63. return "OK"!
  64. $
  65. }