reachability_graph.mvc 1.9 KB

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