reachability_graph.mvc 1.8 KB

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