reachability_graph.mvc 1.7 KB

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