pn_simulate.mvc 7.4 KB

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