merged_mm.od 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. # Auto-generated by /home/maestro/repos/MV2/examples/semantics/translational/regenerate_mm.py.
  2. # Merged run-time meta-models of 'Petri Net' and 'Port' formalisms.
  3. # An abstract 'Top'-class (superclass of everything else), and a 'generic_link'-association (which can connect everything with everything) have also been added.
  4. # PlantUML visualization: https://deemz.org/plantuml/pdf/hPTFYzim4CNl_XGYnqA27P8uDgM7tSEobsmWWHw3RCk9Y2CPMIcKThzxHyuViiMGPwCSzhJpqxoPfz4uo2lUD6pqockUI_lxLQl66YwLPIF66nPUVxkEF-ut2uk8_GaOQmwola5OojwL5NjXWi_WUi1wjQvuBZQMMm6ZborQdKzRVHIgwUB-rEOep4RW-POtw2MqazehJR4WucV0CrUvtB97HdckO4pHZT5dawEvH25l8RUkLZe_icWoYS3mQTmMnygJw2hBYp3sqASsqPnVt44nPrVfZJLIxJjaRdMDCkFuKMDhApGqcJs6thtJIrAIFJBQag2XVFeO-YQKCDng0uSdNuIljeQhHbgf5Kh8mawFhLTqxvN8BSygk0vPtErNgOueelZIZciE9ATNFyhB03hfNtI3KlQYTIMu-iyW_OZtkREXgTOv8AxZ32QMhT3WwN-wAV3zxtZyd3ahn7ESkoiOZkQuJnorrYTkFaDmTBl1xFZKPoleJG6oez4CPfS0Ojsh0-BAfLUZY8LNeuJSAsuQ-nLR-3GArDaUOZD0R0-Z91cGNG5VCaWipLeGDqUCak6r2_rUCg_ZarPVhnE59rvjZ8pF7gqeI-XbNB1Hn2OJHiliUFo3djuHjbMdJ2FpcV9ro1OTkdE-0NmNbJ9kSa00VNdS3uZW0sXdJ5dErKVjbaNapI_BGK92EaUgmmuIuxmtu10Q7YJclkSXHLiEwBehGSfgjOCQ7mzgVEmQltShlCnt5Iszo8AI3JcfTO1iBWPmNqz0rQ8XLalQxbm_uZ_AVm==
  5. CapacityConstraint:Class
  6. PNPlaceState:Class
  7. WorkerSet:Class
  8. State:Class
  9. Stateful:Class {
  10. abstract = True;
  11. }
  12. Source:Class {
  13. abstract = True;
  14. }
  15. Clock:Class {
  16. lower_cardinality = 1;
  17. upper_cardinality = 1;
  18. }
  19. BerthState:Class {
  20. constraint = ```
  21. errors = []
  22. numShips = get_slot_value(this, "numShips")
  23. status = get_slot_value(this, "status")
  24. if (numShips == 0) != (status == "empty"):
  25. errors.append(f"Inconsistent: numShips = {numShips}, but status = {status}")
  26. errors
  27. ```;
  28. }
  29. Top:Class {
  30. abstract = True;
  31. }
  32. Place:Class
  33. WorkerSetState:Class
  34. Berth:Class
  35. Generator:Class
  36. PNTransition:Class
  37. PNConnectable:Class {
  38. abstract = True;
  39. }
  40. Sink:Class {
  41. abstract = True;
  42. }
  43. ConnectionState:Class
  44. PlaceState:Class
  45. PNPlace:Class
  46. shipCapacities:GlobalConstraint {
  47. constraint = ```
  48. errors = []
  49. for _, constr in get_all_instances("CapacityConstraint"):
  50. cap = get_slot_value(constr, "shipCapacity")
  51. total = 0
  52. place_names = [] # for debugging
  53. for lnk in get_outgoing(constr, "capacityOf"):
  54. place = get_target(lnk)
  55. place_names.append(get_name(place))
  56. place_state = get_source(get_incoming(place, "of")[0])
  57. total += get_slot_value(place_state, "numShips")
  58. if total > cap:
  59. errors.append(f"The number of ships in places {','.join(place_names)} ({total}) exceeds the capacity ({cap}) of CapacityConstraint {get_name(constr)}.")
  60. errors
  61. ```;
  62. }
  63. operatingCapacities:GlobalConstraint {
  64. constraint = ```
  65. errors = []
  66. for _, workersetstate in get_all_instances("WorkerSetState"):
  67. workerset = get_target(get_outgoing(workersetstate, "of")[0])
  68. num_operating = len(get_outgoing(workersetstate, "isOperating"))
  69. num_workers = get_slot_value(workerset, "numWorkers")
  70. if num_operating > num_workers:
  71. errors.append(f"WorkerSet {get_name(workerset)} is operating more berths ({num_operating}) than there are workers ({num_workers})")
  72. errors
  73. ```;
  74. }
  75. WorkerSet_numWorkers:AttributeLink (WorkerSet -> Integer) {
  76. name = "numWorkers";
  77. constraint = `get_value(get_target(this)) >= 0`;
  78. optional = False;
  79. }
  80. PlaceState_numShips:AttributeLink (PlaceState -> Integer) {
  81. constraint = `get_value(get_target(this)) >= 0`;
  82. optional = False;
  83. name = "numShips";
  84. }
  85. ConnectionState_moved:AttributeLink (ConnectionState -> Boolean) {
  86. name = "moved";
  87. constraint = ```
  88. result = True
  89. all_successors_moved = True
  90. moved = get_value(get_target(this))
  91. conn_state = get_source(this)
  92. conn = get_target(get_outgoing(conn_state, "of")[0])
  93. tgt_place = get_target(conn)
  94. next_conns = get_outgoing(tgt_place, "connection")
  95. for next_conn in next_conns:
  96. next_conn_state = get_source(get_incoming(next_conn, "of")[0])
  97. if not get_slot_value(next_conn_state, "moved"):
  98. all_successors_moved = False
  99. if moved and not all_successors_moved:
  100. result = f"Connection {get_name(conn)} played before its turn."
  101. result
  102. ```;
  103. optional = False;
  104. }
  105. BerthState_status:AttributeLink (BerthState -> String) {
  106. optional = False;
  107. name = "status";
  108. constraint = ```
  109. (
  110. get_value(get_target(this)) in { "empty", "unserved", "served" }
  111. )
  112. ```;
  113. }
  114. PNPlaceState_numTokens:AttributeLink (PNPlaceState -> Integer) {
  115. name = "numTokens";
  116. constraint = `"numTokens cannot be negative" if get_value(get_target(this)) < 0 else None`;
  117. optional = False;
  118. }
  119. Clock_time:AttributeLink (Clock -> Integer) {
  120. optional = False;
  121. name = "time";
  122. constraint = `get_value(get_target(this)) >= 0`;
  123. }
  124. CapacityConstraint_shipCapacity:AttributeLink (CapacityConstraint -> Integer) {
  125. optional = False;
  126. name = "shipCapacity";
  127. constraint = `get_value(get_target(this)) >= 0`;
  128. }
  129. of:Association (State -> Stateful) {
  130. target_lower_cardinality = 1;
  131. source_upper_cardinality = 1;
  132. source_lower_cardinality = 1;
  133. target_upper_cardinality = 1;
  134. }
  135. arc:Association (PNConnectable -> PNConnectable)
  136. canOperate:Association (WorkerSet -> Berth) {
  137. target_lower_cardinality = 1;
  138. }
  139. inh_arc:Association (PNPlace -> PNTransition)
  140. connection:Association (Source -> Sink)
  141. pn_of:Association (PNPlaceState -> PNPlace) {
  142. source_upper_cardinality = 1;
  143. source_lower_cardinality = 1;
  144. target_upper_cardinality = 1;
  145. target_lower_cardinality = 1;
  146. }
  147. generic_link:Association (Top -> Top)
  148. isOperating:Association (WorkerSetState -> Berth) {
  149. constraint = ```
  150. errors = []
  151. # get status of Berth
  152. berth = get_target(this)
  153. berth_state = get_source(get_incoming(berth, "of")[0])
  154. status = get_slot_value(berth_state, "status")
  155. if status != "unserved":
  156. errors.append(f"Cannot operate {get_name(berth)} because there is no unserved ship there.")
  157. # only operate Berts that we can operate
  158. workerset = get_target(get_outgoing(get_source(this), "of")[0])
  159. can_operate = [get_target(lnk) for lnk in get_outgoing(workerset, "canOperate")]
  160. if berth not in can_operate:
  161. errors.append(f"Cannot operate {get_name(berth)}.")
  162. errors
  163. ```;
  164. }
  165. capacityOf:Association (CapacityConstraint -> Place) {
  166. target_lower_cardinality = 1;
  167. }
  168. :Inheritance (connection -> Stateful)
  169. :Inheritance (CapacityConstraint -> Top)
  170. :Inheritance (Sink -> Top)
  171. :Inheritance (generic_link -> Top)
  172. :Inheritance (Berth -> Place)
  173. :Inheritance (WorkerSet -> Stateful)
  174. :Inheritance (Place -> Source)
  175. :Inheritance (PlaceState -> State)
  176. :Inheritance (State -> Top)
  177. :Inheritance (Source -> Top)
  178. :Inheritance (Clock -> Top)
  179. :Inheritance (Stateful -> Top)
  180. :Inheritance (Place -> Stateful)
  181. :Inheritance (PNConnectable -> Top)
  182. :Inheritance (WorkerSetState -> State)
  183. :Inheritance (Place -> Sink)
  184. :Inheritance (BerthState -> PlaceState)
  185. :Inheritance (PNTransition -> PNConnectable)
  186. :Inheritance (ConnectionState -> State)
  187. :Inheritance (PNPlaceState -> Top)
  188. :Inheritance (Generator -> Source)
  189. :Inheritance (Berth -> Stateful)
  190. :Inheritance (PNPlace -> PNConnectable)