reachability_graph.mvc 1.7 KB

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