reachability_graph.mvc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. name : String
  9. }
  10. Class Place {
  11. name : String
  12. tokens : Natural
  13. }
  14. Association Transition (State, State) {
  15. name : String
  16. }
  17. Association Contains (State, Place) {}
  18. GlobalConstraint {
  19. global_constraint = $
  20. String function constraint(model : Element):
  21. Element states
  22. Element places
  23. String state
  24. String place
  25. Element expected
  26. Element got
  27. states = allInstances(model, "State")
  28. if (read_nr_out(states) > 0):
  29. expected = create_node()
  30. state = set_pop(states)
  31. places = allAssociationDestinations(model, state, "Contains")
  32. while (read_nr_out(places)):
  33. place = set_pop(places)
  34. set_add(expected, read_attribute(model, place, "name"))
  35. else:
  36. return "OK"!
  37. while (read_nr_out(states) > 0):
  38. got = create_node()
  39. state = set_pop(states)
  40. places = allAssociationDestinations(model, state, "Contains")
  41. while (read_nr_out(places)):
  42. place = set_pop(places)
  43. set_add(got, read_attribute(model, place, "name"))
  44. if (bool_not(set_equality(got, expected))):
  45. return "States don't all agree on the set of places"!
  46. return "OK"!
  47. $
  48. }
  49. }