pn_simulate.mvc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import models/RAM_PetriNets_Runtime_Runtime as RAM_PN_R
  2. RAM_PN_R s {
  3. Composite schedule {
  4. {Contains} Failure failure {}
  5. {Contains} Success success {}
  6. {Contains} Atomic mark {
  7. LHS {
  8. Pre_PetriNets_Runtime/Transition {
  9. label = "1"
  10. constraint = $
  11. include "primitives.alh"
  12. include "modelling.alh"
  13. include "object_operations.alh"
  14. Boolean function constraint(host_model : Element, name : String):
  15. Element links
  16. String link
  17. String place
  18. log("Types in metamodel: " + set_to_string(dict_keys(host_model["metamodel"]["model"])))
  19. links = allIncomingAssociationInstances(host_model, name, "PetriNets_Runtime/P2T")
  20. while (read_nr_out(links) > 0):
  21. link = set_pop(links)
  22. place = readAssociationSource(host_model, link)
  23. if (integer_lt(read_attribute(host_model, place, "tokens"), read_attribute(host_model, link, "weight"))):
  24. return False!
  25. return True!
  26. $
  27. }
  28. }
  29. RHS {
  30. Post_PetriNets_Runtime/Transition {
  31. label = "1"
  32. action = $
  33. include "primitives.alh"
  34. include "modelling.alh"
  35. Void function action(host_model : Element, name : String, mapping : Element):
  36. unset_attribute(host_model, name, "executing")
  37. instantiate_attribute(host_model, name, "executing", True)
  38. return!
  39. $
  40. }
  41. }
  42. }
  43. {Contains} ForAll consume {
  44. LHS {
  45. Pre_PetriNets_Runtime/Transition lhs_consume_t{
  46. label = "0"
  47. constraint = $
  48. include "primitives.alh"
  49. include "modelling.alh"
  50. Boolean function constraint(host_model : Element, name : String):
  51. // Check if this node is executing currently
  52. return value_eq(read_attribute(host_model, name, "executing"), True)!
  53. $
  54. }
  55. Pre_PetriNets_Runtime/Place lhs_consume_p{
  56. label = "1"
  57. }
  58. Pre_PetriNets_Runtime/P2T lhs_consume_p2t(lhs_consume_p, lhs_consume_t){
  59. label = "2"
  60. }
  61. }
  62. RHS {
  63. Post_PetriNets_Runtime/Transition rhs_consume_t {
  64. label = "0"
  65. }
  66. Post_PetriNets_Runtime/Place rhs_consume_p {
  67. label = "1"
  68. action = $
  69. include "primitives.alh"
  70. include "modelling.alh"
  71. Void function action(host_model : Element, name : String, mapping : Element):
  72. Integer tokens
  73. Integer weight
  74. tokens = read_attribute(host_model, name, "tokens")
  75. weight = read_attribute(host_model, mapping["2"], "weight")
  76. unset_attribute(host_model, name, "tokens")
  77. instantiate_attribute(host_model, name, "tokens", tokens - weight)
  78. log("Consume for " + cast_v2s(read_attribute(host_model, name, "name")))
  79. log("Previous: " + cast_v2s(tokens))
  80. log("Now: " + cast_v2s(tokens - weight))
  81. return!
  82. $
  83. }
  84. Post_PetriNets_Runtime/P2T (rhs_consume_p, rhs_consume_t){
  85. label = "2"
  86. }
  87. }
  88. }
  89. {Contains} ForAll produce {
  90. LHS {
  91. Pre_PetriNets_Runtime/Transition lhs_produce_t{
  92. label = "0"
  93. constraint = $
  94. include "primitives.alh"
  95. include "modelling.alh"
  96. Boolean function constraint(host_model : Element, name : String):
  97. // Check if this node is executing currently
  98. return value_eq(read_attribute(host_model, name, "executing"), True)!
  99. $
  100. }
  101. Pre_PetriNets_Runtime/Place lhs_produce_p{
  102. label = "1"
  103. }
  104. Pre_PetriNets_Runtime/T2P (lhs_produce_t, lhs_produce_p){
  105. label = "2"
  106. }
  107. }
  108. RHS {
  109. Post_PetriNets_Runtime/Transition rhs_produce_t{
  110. label = "0"
  111. }
  112. Post_PetriNets_Runtime/Place rhs_produce_p{
  113. label = "1"
  114. action = $
  115. include "primitives.alh"
  116. include "modelling.alh"
  117. Void function action(host_model : Element, name : String, mapping : Element):
  118. Integer tokens
  119. Integer weight
  120. tokens = read_attribute(host_model, name, "tokens")
  121. weight = read_attribute(host_model, mapping["2"], "weight")
  122. unset_attribute(host_model, name, "tokens")
  123. instantiate_attribute(host_model, name, "tokens", tokens + weight)
  124. log("Produce for " + cast_v2s(read_attribute(host_model, name, "name")))
  125. log("Previous: " + cast_v2s(tokens))
  126. log("Now: " + cast_v2s(tokens + weight))
  127. return!
  128. $
  129. }
  130. Post_PetriNets_Runtime/T2P (rhs_produce_t, rhs_produce_p){
  131. label = "2"
  132. }
  133. }
  134. }
  135. {Contains} Atomic unmark_transition {
  136. LHS {
  137. Pre_PetriNets_Runtime/Transition {
  138. label = "0"
  139. constraint = $
  140. include "primitives.alh"
  141. include "modelling.alh"
  142. Boolean function constraint(host_model : Element, name : String):
  143. // Check if this node is executing currently
  144. return value_eq(read_attribute(host_model, name, "executing"), True)!
  145. $
  146. }
  147. }
  148. RHS {
  149. Post_PetriNets_Runtime/Transition {
  150. label = "0"
  151. action = $
  152. include "primitives.alh"
  153. include "modelling.alh"
  154. Void function action(host_model : Element, name : String, mapping : Element):
  155. unset_attribute(host_model, name, "executing")
  156. instantiate_attribute(host_model, name, "executing", False)
  157. return!
  158. $
  159. }
  160. }
  161. }
  162. }
  163. OnSuccess (mark, consume) {}
  164. OnFailure (mark, failure) {}
  165. OnSuccess (consume, produce) {}
  166. OnFailure (consume, produce) {}
  167. OnSuccess (produce, unmark_transition) {}
  168. OnFailure (produce, unmark_transition) {}
  169. OnSuccess (unmark_transition, success) {}
  170. OnFailure (unmark_transition, failure) {}
  171. Initial (schedule, mark) {}
  172. }
  173. export s to models/pn_simulate