pn_simulate.mvc 7.4 KB

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