test_pn_interface.py 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. import unittest
  2. from utils import run_file, get_constructor, get_model_constructor
  3. set_inheritance = [
  4. "Which link in the metamodel is the inheritance link?",
  5. "Set inheritance link!",
  6. ]
  7. join = ["Model name?",
  8. "New metamodel?",
  9. ]
  10. unify = ["Which language do you want to unify?",
  11. "Name of this language in the unification",
  12. "Second language to unify?",
  13. "Name of this language in the unification",
  14. ]
  15. ramify = ["Name of the RAMified metamodel to create",
  16. "Source language?"]
  17. transform = ["Which model do you want to transform?",
  18. "Which schedule do you want to execute?",
  19. ]
  20. transform_result_true = ["Transformation result: True"]
  21. split = ["Name of the model to split up?",
  22. "Name of new metamodel?",
  23. "Typename to split?",
  24. ]
  25. do_instantiate_simple = [
  26. "new", "PetriNets", "abc",
  27. "instantiate", "Transition", "t1",
  28. "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
  29. "instantiate", "Place", "p2", "attr_add", "p2", "tokens", 0,
  30. "instantiate", "P2T", "p2t", "p1", "t1", "attr_add", "p2t", "weight", 2,
  31. "instantiate", "T2P", "t2p", "t1", "p2", "attr_add", "t2p", "weight", 1]
  32. instantiate_node = ["Type to instantiate?",
  33. "Name of new element?",
  34. "Instantiation successful!"]
  35. instantiate_edge = ["Type to instantiate?",
  36. "Name of new element?",
  37. "Source name?",
  38. "Destination name?",
  39. "Instantiation successful!"]
  40. all_files = [ "pn_interface.alc",
  41. "primitives.alc",
  42. "object_operations.alc",
  43. "conformance_scd.alc",
  44. "library.alc",
  45. "transform.alc",
  46. "model_management.alc",
  47. "ramify.alc",
  48. "metamodels.alc",
  49. "random.alc",
  50. "constructors.alc",
  51. "modelling.alc",
  52. "compilation_manager.alc",
  53. ]
  54. greeting = ["Welcome to the Model Management Interface, running live on the Modelverse!",
  55. "Use 'help' command for a list of possible commands"]
  56. new = ["Metamodel to instantiate?",
  57. "Name of model?"]
  58. prompt = ["Please give your command."]
  59. loaded = ["Model loaded, ready for commands!",
  60. "Use 'help' command for a list of possible commands"] + prompt
  61. load = ["Model to load?"]
  62. instantiate = ["Type to instantiate?"]
  63. instantiate_name = ["Name of new element?"]
  64. instantiate_ok = ["Instantiation successful!"]
  65. instantiate_source= ["Source name?"]
  66. instantiate_destination = ["Destination name?"]
  67. def list_menu(defined):
  68. defined.append(("PetriNets", "SimpleClassDiagrams"))
  69. defined.append(("SimpleClassDiagrams", "SimpleClassDiagrams"))
  70. defined.append(("LTM_bottom", "LTM_bottom"))
  71. return ["Found models:",
  72. set([" %s : %s" % (m, mm) for m, mm in defined])]
  73. def list_model(defined):
  74. return ["List of all elements:",
  75. set([" %s : %s" % (m, mm) for m, mm in defined])]
  76. def read_node(name, t, defs, attrs):
  77. return ["Element to read?",
  78. "Name: %s" % name,
  79. "Type: %s" % t,
  80. "Defines attributes:"] + \
  81. ([set([" %s : %s" % (m, mm) for m, mm in defs])] if defs else []) + \
  82. ["Attributes:"] + \
  83. ([set([' "%s" : "%s" = %s' % (m, mm, v) for m, mm, v in attrs])] if attrs else [])
  84. def read_edge(name, t, src, dst, defs, attrs):
  85. return ["Element to read?",
  86. "Name: %s" % name,
  87. "Type: %s" % t,
  88. "Source: %s" % src,
  89. "Destination: %s" % dst,
  90. "Defines attributes:"] + \
  91. ([set([" %s : %s" % (m, mm) for m, mm in defs])] if defs else []) + \
  92. ["Attributes:"] + \
  93. ([set([' "%s" : "%s" = %s' % (m, mm, v) for m, mm, v in attrs])] if attrs else [])
  94. delete = ["Model to delete?", "Deleted!"]
  95. rename = ["Old name?", "New name?", "Rename complete!"]
  96. attr_add = ["Which model do you want to assign an attribute to?",
  97. "Which attribute do you wish to assign?",
  98. "Value of attribute?",
  99. "Added attribute!"]
  100. attr_del = ["Which model do you want to remove an attribute of?",
  101. "Which attribute do you want to delete?",
  102. "Attribute deleted!",
  103. ]
  104. help_root = ["Currently no model is loaded, so your operations are limited to:",
  105. " new -- Create a new model and save it for future use"
  106. " load -- Load a previously made model",
  107. " rename -- Rename a previously made model",
  108. " delete -- Delete a previously made model",
  109. " list -- Show a list of all stored models",
  110. " help -- Show a list of possible commands"]
  111. verify_fail_weight= ["Natural number not larger than or equal to zero"]
  112. verify_fail_tokens= ["Natural number not larger than or equal to zero"]
  113. verify_fail_structure = ["Source of model edge not typed by source of type: p2t"]
  114. init = greeting + prompt
  115. did_instantiate_simple = init + \
  116. new + \
  117. loaded +\
  118. instantiate_node + \
  119. prompt + \
  120. instantiate_node + \
  121. prompt + \
  122. attr_add + \
  123. prompt + \
  124. instantiate_node + \
  125. prompt + \
  126. attr_add + \
  127. prompt + \
  128. instantiate_edge + \
  129. prompt + \
  130. attr_add + \
  131. prompt + \
  132. instantiate_edge + \
  133. prompt + \
  134. attr_add + \
  135. prompt
  136. def list_types(t):
  137. return ["List of types:"] + \
  138. [set([" %s : %s" % (m, mm) for m, mm in t])]
  139. modify = ["Element to modify?",
  140. "Attribute to modify?",
  141. "New value?",
  142. "Modified!",]
  143. class TestPetrinetInterface(unittest.TestCase):
  144. def test_po_pn_interface_manage(self):
  145. self.pn_interface_manage("PO")
  146. def test_co_pn_interface_manage(self):
  147. self.pn_interface_manage("CO")
  148. def pn_interface_manage(self, mode):
  149. self.assertTrue(run_file(all_files,
  150. ["list",
  151. "new", "PetriNets", "abc", "exit",
  152. "list",
  153. "new", "PetriNets", "def", "exit",
  154. "list",
  155. "delete", "def",
  156. "list",
  157. "rename", "abc", "a",
  158. "list",
  159. "delete", "a",
  160. "list",
  161. ],
  162. init + \
  163. list_menu([]) + prompt + \
  164. new + loaded + prompt + list_menu([("abc", "PetriNets")]) + prompt + \
  165. new + loaded + prompt + list_menu([("abc", "PetriNets"), ("def", "PetriNets")]) + prompt + \
  166. delete + prompt + list_menu([("abc", "PetriNets")]) + prompt + \
  167. rename + prompt + list_menu([("a", "PetriNets")]) + prompt + \
  168. delete + prompt + list_menu([]) + prompt,
  169. mode))
  170. def test_po_pn_interface_new_reload(self):
  171. self.pn_interface_new_reload("PO")
  172. def test_co_pn_interface_new_reload(self):
  173. self.pn_interface_new_reload("CO")
  174. def pn_interface_new_reload(self, mode):
  175. self.assertTrue(run_file(all_files,
  176. ["new", "PetriNets", "abc", "exit", "load", "abc"],
  177. init + new + loaded + prompt + load + loaded,
  178. mode))
  179. def test_po_pn_interface_instantiate_place(self):
  180. self.pn_interface_instantiate_place("PO")
  181. def test_co_pn_interface_instantiate_place(self):
  182. self.pn_interface_instantiate_place("CO")
  183. def pn_interface_instantiate_place(self, mode):
  184. self.assertTrue(run_file(all_files,
  185. ["new", "PetriNets", "abc",
  186. "instantiate", "Place", "p1",
  187. "attr_add", "p1", "tokens", 5,
  188. "list",
  189. "read", "p1",
  190. "instantiate", "Transition", "t1",
  191. "list",
  192. "read", "t1"],
  193. init + new + loaded + \
  194. instantiate_node + prompt + \
  195. attr_add + prompt + \
  196. list_model([("p1", "Place"), ("p1.tokens", "Natural")]) + prompt + \
  197. read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
  198. instantiate_node + prompt + \
  199. list_model([("p1", "Place"), ("t1", "Transition"), ("p1.tokens", "Natural")]) + prompt + \
  200. read_node("t1", "Transition", [], []) + prompt,
  201. mode))
  202. def test_po_pn_interface_instantiate_arcs(self):
  203. self.pn_interface_instantiate_arcs("PO")
  204. def test_co_pn_interface_instantiate_arcs(self):
  205. self.pn_interface_instantiate_arcs("CO")
  206. def pn_interface_instantiate_arcs(self, mode):
  207. self.assertTrue(run_file(all_files,
  208. do_instantiate_simple + [
  209. "read", "p1",
  210. "read", "p2",
  211. "read", "t1",
  212. "read", "p2t",
  213. "read", "t2p",
  214. ],
  215. did_instantiate_simple + \
  216. read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
  217. read_node("p2", "Place", [], [("tokens", "Natural", 0)]) + prompt + \
  218. read_node("t1", "Transition", [], []) + prompt + \
  219. read_edge("p2t", "P2T", "p1", "t1", [], [("weight", "Natural", 2)]) + prompt + \
  220. read_edge("t2p", "T2P", "t1", "p2", [], [("weight", "Natural", 1)]) + prompt,
  221. mode))
  222. def test_po_pn_interface_verify_OK(self):
  223. self.pn_interface_verify_OK("PO")
  224. def test_co_pn_interface_verify_OK(self):
  225. self.pn_interface_verify_OK("CO")
  226. def pn_interface_verify_OK(self, mode):
  227. self.assertTrue(run_file(all_files,
  228. do_instantiate_simple + ["verify"],
  229. did_instantiate_simple + ["OK"], mode))
  230. def test_po_pn_interface_verify_fail_tokens(self):
  231. self.pn_interface_verify_fail_tokens("PO")
  232. def test_co_pn_interface_verify_fail_tokens(self):
  233. self.pn_interface_verify_fail_tokens("CO")
  234. def pn_interface_verify_fail_tokens(self, mode):
  235. self.assertTrue(run_file(all_files,
  236. do_instantiate_simple + ["modify", "p1", "tokens", -5, "verify"],
  237. did_instantiate_simple + modify + prompt + verify_fail_tokens + prompt, mode))
  238. def test_po_pn_interface_verify_fail_weight(self):
  239. self.pn_interface_verify_fail_weight("PO")
  240. def test_co_pn_interface_verify_fail_weight(self):
  241. self.pn_interface_verify_fail_weight("CO")
  242. def pn_interface_verify_fail_weight(self, mode):
  243. self.assertTrue(run_file(all_files,
  244. do_instantiate_simple + ["modify", "p2t", "weight", -2, "verify"],
  245. did_instantiate_simple + modify + prompt + verify_fail_weight + prompt, mode))
  246. def test_po_pn_interface_verify_fail_structure(self):
  247. self.pn_interface_verify_fail_structure("PO")
  248. def test_co_pn_interface_verify_fail_structure(self):
  249. self.pn_interface_verify_fail_structure("CO")
  250. def pn_interface_verify_fail_structure(self, mode):
  251. self.assertTrue(run_file(all_files,
  252. ["new", "PetriNets", "abc",
  253. "instantiate", "Transition", "t1",
  254. "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
  255. "instantiate", "P2T", "p2t", "t1", "p1", "attr_add", "p2t", "weight", 2, "verify"],
  256. init + new + loaded + \
  257. instantiate_node + prompt + \
  258. instantiate_node + prompt + attr_add + prompt + \
  259. instantiate_edge + prompt + attr_add + prompt + \
  260. verify_fail_structure,
  261. mode))
  262. def test_po_pn_interface_types(self):
  263. self.pn_interface_types("PO")
  264. def test_co_pn_interface_types(self):
  265. self.pn_interface_types("CO")
  266. def pn_interface_types(self, mode):
  267. self.assertTrue(run_file(all_files,
  268. ["new", "PetriNets", "abc", "types"],
  269. init + new + loaded + list_types([("Place", "Class"),
  270. ("Transition", "Class"),
  271. ("P2T", "Association"),
  272. ("T2P", "Association"),
  273. ("Natural", "Class"),
  274. ("Place_tokens", "Association"),
  275. ("Place_tokens.name", "String"),
  276. ("Place_tokens.target_lower_cardinality", "Natural"),
  277. ("Place_tokens.target_upper_cardinality", "Natural"),
  278. ("P2T_weight", "Association"),
  279. ("P2T_weight.name", "String"),
  280. ("P2T_weight.target_lower_cardinality", "Natural"),
  281. ("P2T_weight.target_upper_cardinality", "Natural"),
  282. ("T2P_weight", "Association"),
  283. ("T2P_weight.name", "String"),
  284. ("T2P_weight.target_lower_cardinality", "Natural"),
  285. ("T2P_weight.target_upper_cardinality", "Natural"),
  286. ]) + prompt,
  287. mode))
  288. def test_po_pn_interface_modify_place(self):
  289. self.pn_interface_modify_place("PO")
  290. def test_co_pn_interface_modify_place(self):
  291. self.pn_interface_modify_place("CO")
  292. def pn_interface_modify_place(self, mode):
  293. self.assertTrue(run_file(all_files,
  294. ["new", "PetriNets", "abc",
  295. "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
  296. "read", "p1",
  297. "modify", "p1", "tokens", 1, "read", "p1"],
  298. init + new + loaded + \
  299. instantiate_node + prompt + attr_add + prompt + \
  300. read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
  301. modify + prompt + \
  302. read_node("p1", "Place", [], [("tokens", "Natural", 1)]) + prompt,
  303. mode))
  304. def test_po_pn_interface_verify_fail_attr_lower_cardinality(self):
  305. self.pn_interface_verify_fail_attr_lower_cardinality("PO")
  306. def test_co_pn_interface_verify_fail_attr_lower_cardinality(self):
  307. self.pn_interface_verify_fail_attr_lower_cardinality("CO")
  308. def pn_interface_verify_fail_attr_lower_cardinality(self, mode):
  309. self.assertTrue(run_file(all_files,
  310. do_instantiate_simple + ["instantiate", "Place", "p999", "verify"],
  311. did_instantiate_simple + instantiate_node + prompt + ["Lower cardinality violation for outgoing edge of type Place_tokens at p999"] + prompt,
  312. mode))
  313. def test_po_pn_interface_verify_fail_attr_upper_cardinality(self):
  314. self.pn_interface_verify_fail_attr_upper_cardinality("PO")
  315. def test_co_pn_interface_verify_fail_attr_upper_cardinality(self):
  316. self.pn_interface_verify_fail_attr_upper_cardinality("CO")
  317. def pn_interface_verify_fail_attr_upper_cardinality(self, mode):
  318. self.assertTrue(run_file(all_files,
  319. do_instantiate_simple + ["attr_add", "p1", "tokens", 5, "verify"],
  320. did_instantiate_simple + attr_add + prompt + ["Upper cardinality violation for outgoing edge of type Place_tokens at p1"] + prompt,
  321. mode))
  322. def test_po_pn_interface_verify_natural(self):
  323. self.pn_interface_verify_natural("PO")
  324. def test_co_pn_interface_verify_natural(self):
  325. self.pn_interface_verify_natural("CO")
  326. def pn_interface_verify_natural(self, mode):
  327. self.assertTrue(run_file(all_files,
  328. ["new", "PetriNets", "abc",
  329. "instantiate", "Place", "p1",
  330. "attr_add", "p1", "tokens", -5,
  331. "attr_del", "p1", "tokens",
  332. "attr_add", "p1", "tokens", 4,
  333. "verify"],
  334. init + new + loaded + \
  335. instantiate_node + prompt + \
  336. attr_add + prompt + \
  337. attr_del + prompt + \
  338. attr_add + prompt + \
  339. ["OK"] + prompt,
  340. mode))
  341. def test_po_pn_interface_verify_PN_OK(self):
  342. self.pn_interface_verify_PN_OK("PO")
  343. def test_co_pn_interface_verify_PN_OK(self):
  344. self.pn_interface_verify_PN_OK("CO")
  345. def pn_interface_verify_PN_OK(self, mode):
  346. self.assertTrue(run_file(all_files,
  347. ["load", "PetriNets", "verify"],
  348. init + load + loaded + ["OK"], mode))
  349. def test_po_rpgame(self):
  350. self.rpgame("PO")
  351. def test_co_rpgame(self):
  352. self.rpgame("CO")
  353. def rpgame(self, mode):
  354. constraint_code = \
  355. """
  356. include "primitives.alh"
  357. include "object_operations.alh"
  358. Element function constraint(model : Element, name : String):
  359. Element associations
  360. Element back_associations
  361. Element association
  362. String destination
  363. associations = allOutgoingAssociationInstances(model, name, "tile_left")
  364. while (0 < list_len(associations)):
  365. association = set_pop(associations)
  366. destination = readAssociationDestination(model, association)
  367. back_associations = allOutgoingAssociationInstances(model, destination, "tile_right")
  368. if (list_len(back_associations) < 1):
  369. return "Left link does not have a right link back"!
  370. else:
  371. association = set_pop(back_associations)
  372. destination = readAssociationDestination(model, association)
  373. if (destination != name):
  374. return "Right link does not have a left link back to the same tile"!
  375. associations = allOutgoingAssociationInstances(model, name, "tile_right")
  376. while (0 < list_len(associations)):
  377. association = set_pop(associations)
  378. destination = readAssociationDestination(model, association)
  379. back_associations = allOutgoingAssociationInstances(model, destination, "tile_left")
  380. if (list_len(back_associations) < 1):
  381. return "Right link does not have a left link back"!
  382. else:
  383. association = set_pop(back_associations)
  384. destination = readAssociationDestination(model, association)
  385. if (destination != name):
  386. return "Right link does not have a left link back to the same tile"!
  387. associations = allOutgoingAssociationInstances(model, name, "tile_top")
  388. while (0 < list_len(associations)):
  389. association = set_pop(associations)
  390. destination = readAssociationDestination(model, association)
  391. back_associations = allOutgoingAssociationInstances(model, destination, "tile_bottom")
  392. if (list_len(back_associations) < 1):
  393. return "Top link does not have a bottom link back"!
  394. else:
  395. association = set_pop(back_associations)
  396. destination = readAssociationDestination(model, association)
  397. if (destination != name):
  398. return "Top link does not have a bottom link back to the same tile"!
  399. associations = allOutgoingAssociationInstances(model, name, "tile_bottom")
  400. while (0 < list_len(associations)):
  401. association = set_pop(associations)
  402. destination = readAssociationDestination(model, association)
  403. back_associations = allOutgoingAssociationInstances(model, destination, "tile_top")
  404. if (list_len(back_associations) < 1):
  405. return "Bottom link does not have a top link back"!
  406. else:
  407. association = set_pop(back_associations)
  408. destination = readAssociationDestination(model, association)
  409. if (destination != name):
  410. return "Bottom link does not have a top link back to the same tile"!
  411. return "OK"!
  412. """
  413. constructors = get_constructor(constraint_code)
  414. self.assertTrue(run_file(all_files,
  415. ["new", "SimpleClassDiagrams", "RPGame",
  416. "set_inheritance", "Inheritance",
  417. "instantiate", "Class", "Scene",
  418. "instantiate", "Class", "Tile",
  419. "instantiate", "Class", "Item",
  420. "instantiate", "Class", "Goal",
  421. "instantiate", "Class", "Character",
  422. "instantiate", "Class", "Hero",
  423. "instantiate", "Association", "scene_has_tiles", "Scene", "Tile",
  424. "instantiate", "Association", "tile_left", "Tile", "Tile",
  425. "instantiate", "Association", "tile_right", "Tile", "Tile",
  426. "instantiate", "Association", "tile_top", "Tile", "Tile",
  427. "instantiate", "Association", "tile_bottom", "Tile", "Tile",
  428. "instantiate", "Association", "character_on", "Character", "Tile",
  429. "instantiate", "Association", "item_on", "Item", "Tile",
  430. "instantiate", "Inheritance", "hero_is_character", "Hero", "Character",
  431. "instantiate", "Inheritance", "goal_is_item", "Goal", "Item",
  432. "attr_add", "Scene", "lower_cardinality", 1,
  433. "attr_add", "Scene", "upper_cardinality", 1,
  434. "attr_add", "Goal", "lower_cardinality", 1,
  435. "attr_add", "scene_has_tiles", "source_lower_cardinality", 1,
  436. "attr_add", "scene_has_tiles", "source_upper_cardinality", 1,
  437. "attr_add", "scene_has_tiles", "target_lower_cardinality", 1,
  438. "attr_add", "item_on", "target_lower_cardinality", 1,
  439. "attr_add", "item_on", "target_upper_cardinality", 1,
  440. "attr_add", "item_on", "source_upper_cardinality", 1,
  441. "attr_add", "character_on", "target_lower_cardinality", 1,
  442. "attr_add", "character_on", "target_upper_cardinality", 1,
  443. "attr_add", "character_on", "source_upper_cardinality", 1,
  444. "attr_add", "tile_left", "source_upper_cardinality", 1,
  445. "attr_add", "tile_left", "target_upper_cardinality", 1,
  446. "attr_add", "tile_right", "source_upper_cardinality", 1,
  447. "attr_add", "tile_right", "target_upper_cardinality", 1,
  448. "attr_add", "tile_top", "source_upper_cardinality", 1,
  449. "attr_add", "tile_top", "target_upper_cardinality", 1,
  450. "attr_add", "tile_bottom", "source_upper_cardinality", 1,
  451. "attr_add", "tile_bottom", "target_upper_cardinality", 1,
  452. "attr_add_code", "Tile", "constraint",
  453. ] + constructors + ["verify"] + ["exit"] + [
  454. "new", "RPGame", "my_game",
  455. "instantiate", "Scene", "scene",
  456. "instantiate", "Hero", "Link",
  457. "instantiate", "Goal", "goal",
  458. "instantiate", "Tile", "tile_00",
  459. "instantiate", "Tile", "tile_01",
  460. "instantiate", "Tile", "tile_10",
  461. "instantiate", "Tile", "tile_11",
  462. "instantiate", "scene_has_tiles", "", "scene", "tile_00",
  463. "instantiate", "scene_has_tiles", "", "scene", "tile_01",
  464. "instantiate", "scene_has_tiles", "", "scene", "tile_10",
  465. "instantiate", "scene_has_tiles", "", "scene", "tile_11",
  466. "instantiate", "character_on", "", "Link", "tile_00",
  467. "instantiate", "item_on", "", "goal", "tile_11",
  468. "instantiate", "tile_left", "", "tile_01", "tile_00",
  469. "instantiate", "tile_left", "", "tile_11", "tile_10",
  470. "instantiate", "tile_right", "", "tile_00", "tile_01",
  471. "instantiate", "tile_right", "", "tile_10", "tile_11",
  472. "instantiate", "tile_top", "", "tile_10", "tile_00",
  473. "instantiate", "tile_top", "", "tile_11", "tile_01",
  474. "instantiate", "tile_bottom", "", "tile_00", "tile_10",
  475. "instantiate", "tile_bottom", "", "tile_01", "tile_11",
  476. "verify",
  477. ],
  478. init + new + loaded + \
  479. set_inheritance + prompt + \
  480. (instantiate_node + prompt) * 6 + \
  481. (instantiate_edge + prompt) * 9 + \
  482. (attr_add + prompt) * 20 + \
  483. ["Which model do you want to assign a coded attribute to?",
  484. "Which attribute do you wish to assign?",
  485. "Constructors for code?",
  486. "Added code!"] + \
  487. prompt + \
  488. ["OK"] + \
  489. prompt + prompt + new + loaded + \
  490. (instantiate_node + prompt) * 7 + \
  491. (instantiate_edge + prompt) * 14 + \
  492. ["OK"],
  493. mode))
  494. def test_po_pn_interface_model_transform_pn(self):
  495. PN_runtime = \
  496. """
  497. import models/SimpleClassDiagrams as SimpleClassDiagrams
  498. SimpleClassDiagrams PetriNets_Runtime{
  499. Class Natural {}
  500. Class Boolean {}
  501. Class Place {
  502. tokens : Natural
  503. }
  504. Class Transition {
  505. executing : Boolean
  506. }
  507. Association P2T (Place, Transition) {
  508. weight : Natural
  509. }
  510. Association T2P (Transition, Place) {
  511. weight : Natural
  512. }
  513. }
  514. export PetriNets_Runtime to models/PetriNets_Runtime
  515. """
  516. PN_model = \
  517. """
  518. import models/PetriNets_Runtime as PetriNets_Runtime
  519. PetriNets_Runtime pn {
  520. Place p1 {
  521. tokens = 1
  522. }
  523. Place p2 {
  524. tokens = 2
  525. }
  526. Place p3 {
  527. tokens = 3
  528. }
  529. Transition t1 {
  530. executing = False
  531. }
  532. P2T (p1, t1) {
  533. weight = 1
  534. }
  535. P2T (p2, t1) {
  536. weight = 1
  537. }
  538. T2P (t1, p3) {
  539. weight = 2
  540. }
  541. }
  542. export pn to models/pn
  543. """
  544. schedule_model = \
  545. """
  546. import models/PetriNets_Runtime_SCHEDULE as PN_Transform
  547. PN_Transform s {
  548. Composite schedule {
  549. {Contains} Failure failure {}
  550. {Contains} Success success {}
  551. {Contains} Atomic mark {
  552. LHS {
  553. Pre_Transition {
  554. label = "1"
  555. constraint = $
  556. include "primitives.alh"
  557. include "modelling.alh"
  558. include "object_operations.alh"
  559. Boolean function constraint(host_model : Element, name : String):
  560. Element links
  561. String link
  562. String place
  563. links = allIncomingAssociationInstances(host_model, name, "P2T")
  564. while (read_nr_out(links) > 0):
  565. link = set_pop(links)
  566. place = readAssociationSource(host_model, link)
  567. if (integer_lt(read_attribute(host_model, place, "tokens"), read_attribute(host_model, link, "weight"))):
  568. return False!
  569. return True!
  570. $
  571. }
  572. }
  573. RHS {
  574. Post_Transition {
  575. label = "1"
  576. action = $
  577. include "primitives.alh"
  578. include "modelling.alh"
  579. Void function action(host_model : Element, name : String, mapping : Element):
  580. unset_attribute(host_model, name, "executing")
  581. instantiate_attribute(host_model, name, "executing", True)
  582. return!
  583. $
  584. }
  585. }
  586. }
  587. {Contains} ForAll consume {
  588. LHS {
  589. Pre_Transition lhs_consume_t{
  590. label = "0"
  591. constraint = $
  592. include "primitives.alh"
  593. include "modelling.alh"
  594. Boolean function constraint(host_model : Element, name : String):
  595. // Check if this node is executing currently
  596. return value_eq(read_attribute(host_model, name, "executing"), True)!
  597. $
  598. }
  599. Pre_Place lhs_consume_p{
  600. label = "1"
  601. }
  602. Pre_P2T lhs_consume_p2t(lhs_consume_p, lhs_consume_t){
  603. label = "2"
  604. }
  605. }
  606. RHS {
  607. Post_Transition rhs_consume_t {
  608. label = "0"
  609. }
  610. Post_Place rhs_consume_p {
  611. label = "1"
  612. action = $
  613. include "primitives.alh"
  614. include "modelling.alh"
  615. Void function action(host_model : Element, name : String, mapping : Element):
  616. Integer tokens
  617. Integer weight
  618. tokens = read_attribute(host_model, name, "tokens")
  619. weight = read_attribute(host_model, mapping["2"], "weight")
  620. unset_attribute(host_model, name, "tokens")
  621. instantiate_attribute(host_model, name, "tokens", tokens - weight)
  622. return!
  623. $
  624. }
  625. Post_P2T (rhs_consume_p, rhs_consume_t){
  626. label = "2"
  627. }
  628. }
  629. }
  630. {Contains} ForAll produce {
  631. LHS {
  632. Pre_Transition lhs_produce_t{
  633. label = "0"
  634. constraint = $
  635. include "primitives.alh"
  636. include "modelling.alh"
  637. Boolean function constraint(host_model : Element, name : String):
  638. // Check if this node is executing currently
  639. return value_eq(read_attribute(host_model, name, "executing"), True)!
  640. $
  641. }
  642. Pre_Place lhs_produce_p{
  643. label = "1"
  644. }
  645. Pre_T2P (lhs_produce_t, lhs_produce_p){
  646. label = "2"
  647. }
  648. }
  649. RHS {
  650. Post_Transition rhs_produce_t{
  651. label = "0"
  652. }
  653. Post_Place rhs_produce_p{
  654. label = "1"
  655. action = $
  656. include "primitives.alh"
  657. include "modelling.alh"
  658. Void function action(host_model : Element, name : String, mapping : Element):
  659. Integer tokens
  660. Integer weight
  661. tokens = read_attribute(host_model, name, "tokens")
  662. weight = read_attribute(host_model, mapping["2"], "weight")
  663. unset_attribute(host_model, name, "tokens")
  664. instantiate_attribute(host_model, name, "tokens", tokens + weight)
  665. return!
  666. $
  667. }
  668. Post_T2P (rhs_produce_t, rhs_produce_p){
  669. label = "2"
  670. }
  671. }
  672. }
  673. {Contains} Atomic unmark_transition {
  674. LHS {
  675. Pre_Transition {
  676. label = "0"
  677. constraint = $
  678. include "primitives.alh"
  679. include "modelling.alh"
  680. Boolean function constraint(host_model : Element, name : String):
  681. // Check if this node is executing currently
  682. return value_eq(read_attribute(host_model, name, "executing"), True)!
  683. $
  684. }
  685. }
  686. RHS {
  687. Post_Transition {
  688. label = "0"
  689. action = $
  690. include "primitives.alh"
  691. include "modelling.alh"
  692. Void function action(host_model : Element, name : String, mapping : Element):
  693. unset_attribute(host_model, name, "executing")
  694. instantiate_attribute(host_model, name, "executing", False)
  695. return!
  696. $
  697. }
  698. }
  699. }
  700. }
  701. OnSuccess (mark, consume) {}
  702. OnFailure (mark, failure) {}
  703. OnSuccess (consume, produce) {}
  704. OnFailure (consume, produce) {}
  705. OnSuccess (produce, unmark_transition) {}
  706. OnFailure (produce, unmark_transition) {}
  707. OnSuccess (unmark_transition, success) {}
  708. OnFailure (unmark_transition, failure) {}
  709. Initial (schedule, mark) {}
  710. }
  711. export s to models/pn_simulate
  712. """
  713. self.assertTrue(run_file(all_files,
  714. get_model_constructor(PN_runtime) + [
  715. ] + get_model_constructor(PN_model) + [
  716. "load", "pn",
  717. "read", "t1",
  718. "read", "p1",
  719. "read", "p2",
  720. "read", "p3",
  721. "exit",
  722. "ramify", "PetriNets_Runtime_SCHEDULE", "PetriNets_Runtime",
  723. ] + get_model_constructor(schedule_model) + [
  724. "transform", "pn", "pn_simulate",
  725. "load", "pn",
  726. "verify",
  727. "read", "t1",
  728. "read", "p1",
  729. "read", "p2",
  730. "read", "p3",
  731. "exit",
  732. ],
  733. greeting + prompt * 3 +
  734. load + loaded +
  735. read_node("t1", "Transition", [], [("executing", "Boolean", False)]) + prompt +
  736. read_node("p1", "Place", [], [("tokens", "Natural", 1)]) + prompt +
  737. read_node("p2", "Place", [], [("tokens", "Natural", 2)]) + prompt +
  738. read_node("p3", "Place", [], [("tokens", "Natural", 3)]) + prompt +
  739. prompt +
  740. ramify + prompt +
  741. prompt +
  742. transform + transform_result_true + prompt +
  743. load + loaded +
  744. ["OK"] + prompt +
  745. read_node("t1", "Transition", [], [("executing", "Boolean", False)]) + prompt +
  746. read_node("p1", "Place", [], [("tokens", "Natural", 0)]) + prompt +
  747. read_node("p2", "Place", [], [("tokens", "Natural", 1)]) + prompt +
  748. read_node("p3", "Place", [], [("tokens", "Natural", 5)]) + prompt,
  749. "PO"))
  750. def test_po_pn_interface_transform_pn_to_runtime(self):
  751. PN_runtime = \
  752. """
  753. import models/SimpleClassDiagrams as SimpleClassDiagrams
  754. SimpleClassDiagrams PetriNets_Design{
  755. Class Natural {}
  756. Class Place {
  757. tokens : Natural
  758. }
  759. Class Transition {}
  760. Association P2T (Place, Transition) {
  761. weight : Natural
  762. }
  763. Association T2P (Transition, Place) {
  764. weight : Natural
  765. }
  766. }
  767. SimpleClassDiagrams PetriNets_Runtime{
  768. Class Natural {}
  769. Class Boolean {}
  770. Class String {}
  771. Class Place {
  772. tokens : Natural
  773. name : String
  774. }
  775. Class Transition {
  776. executing : Boolean
  777. }
  778. Association P2T (Place, Transition) {
  779. weight : Natural
  780. }
  781. Association T2P (Transition, Place) {
  782. weight : Natural
  783. }
  784. }
  785. export PetriNets_Design to models/PetriNets_Design
  786. export PetriNets_Runtime to models/PetriNets_Runtime
  787. """
  788. PN_model = \
  789. """
  790. import models/PetriNets_Design as PetriNets
  791. PetriNets pn {
  792. Place p1 {
  793. tokens = 1
  794. }
  795. Place p2 {
  796. tokens = 2
  797. }
  798. Place p3 {
  799. tokens = 3
  800. }
  801. Transition t1 {}
  802. P2T (p1, t1) {
  803. weight = 1
  804. }
  805. P2T (p2, t1) {
  806. weight = 1
  807. }
  808. T2P (t1, p3) {
  809. weight = 2
  810. }
  811. }
  812. export pn to models/pn
  813. """
  814. schedule_model_annotate = \
  815. """
  816. import models/RAM_PetriNets_Design_Runtime as RAM_PN_DR
  817. RAM_PN_DR annotate {
  818. Composite schedule {
  819. {Contains} Failure failure {}
  820. {Contains} Success success {}
  821. {Contains} ForAll copy_transitions {
  822. LHS {
  823. Pre_SOURCE_Transition {
  824. label = "0"
  825. }
  826. }
  827. RHS {
  828. Post_SOURCE_Transition ct1 {
  829. label = "0"
  830. }
  831. Post_TARGET_Transition ct2 {
  832. label = "1"
  833. action = $
  834. include "primitives.alh"
  835. include "modelling.alh"
  836. Void function action(host_model : Element, name : String, mapping : Element):
  837. instantiate_attribute(host_model, name, "executing", False)
  838. return!
  839. $
  840. }
  841. Post_TransitionLink (ct1, ct2){
  842. label = "2"
  843. }
  844. }
  845. }
  846. {Contains} ForAll copy_places {
  847. LHS {
  848. Pre_SOURCE_Place {
  849. label = "0"
  850. }
  851. }
  852. RHS {
  853. Post_SOURCE_Place cp1 {
  854. label = "0"
  855. }
  856. Post_TARGET_Place cp2 {
  857. label = "1"
  858. action = $
  859. include "primitives.alh"
  860. include "modelling.alh"
  861. Void function action(host_model : Element, name : String, mapping : Element):
  862. instantiate_attribute(host_model, name, "tokens", read_attribute(host_model, mapping["0"], "tokens"))
  863. instantiate_attribute(host_model, name, "name", mapping["0"])
  864. return!
  865. $
  866. }
  867. Post_PlaceLink (cp1, cp2){
  868. label = "2"
  869. }
  870. }
  871. }
  872. {Contains} ForAll copy_P2T {
  873. LHS {
  874. Pre_SOURCE_Place cp2t_p{
  875. label = "0"
  876. }
  877. Pre_SOURCE_Transition cp2t_t{
  878. label = "1"
  879. }
  880. Pre_SOURCE_P2T (cp2t_p, cp2t_t){
  881. label = "2"
  882. }
  883. Pre_TARGET_Place cp2t_p2{
  884. label = "3"
  885. }
  886. Pre_TARGET_Transition cp2t_t2{
  887. label = "4"
  888. }
  889. Pre_PlaceLink (cp2t_p, cp2t_p2){
  890. label = "5"
  891. }
  892. Pre_TransitionLink (cp2t_t, cp2t_t2){
  893. label = "6"
  894. }
  895. }
  896. RHS {
  897. Post_SOURCE_Place rhs_cp2t_p{
  898. label = "0"
  899. }
  900. Post_SOURCE_Transition rhs_cp2t_t{
  901. label = "1"
  902. }
  903. Post_SOURCE_P2T rhs_cp2t_p2t (rhs_cp2t_p, rhs_cp2t_t){
  904. label = "2"
  905. }
  906. Post_TARGET_Place rhs_cp2t_p2 {
  907. label = "3"
  908. }
  909. Post_TARGET_Transition rhs_cp2t_t2 {
  910. label = "4"
  911. }
  912. Post_PlaceLink (rhs_cp2t_p, rhs_cp2t_p2){
  913. label = "5"
  914. }
  915. Post_TransitionLink (rhs_cp2t_t, rhs_cp2t_t2){
  916. label = "6"
  917. }
  918. Post_TARGET_P2T rhs_cp2t_p2t2(rhs_cp2t_p2, rhs_cp2t_t2) {
  919. label = "7"
  920. action = $
  921. include "primitives.alh"
  922. include "modelling.alh"
  923. Void function action(host_model : Element, name : String, mapping : Element):
  924. instantiate_attribute(host_model, name, "weight", read_attribute(host_model, mapping["2"], "weight"))
  925. return!
  926. $
  927. }
  928. }
  929. }
  930. {Contains} ForAll copy_T2P {
  931. LHS {
  932. Pre_SOURCE_Place ct2p_p{
  933. label = "0"
  934. }
  935. Pre_SOURCE_Transition ct2p_t{
  936. label = "1"
  937. }
  938. Pre_SOURCE_T2P (ct2p_t, ct2p_p){
  939. label = "2"
  940. }
  941. Pre_TARGET_Place ct2p_p2{
  942. label = "3"
  943. }
  944. Pre_TARGET_Transition ct2p_t2{
  945. label = "4"
  946. }
  947. Pre_PlaceLink (ct2p_p, ct2p_p2){
  948. label = "5"
  949. }
  950. Pre_TransitionLink (ct2p_t, ct2p_t2){
  951. label = "6"
  952. }
  953. }
  954. RHS {
  955. Post_SOURCE_Place rhs_ct2p_p{
  956. label = "0"
  957. }
  958. Post_SOURCE_Transition rhs_ct2p_t{
  959. label = "1"
  960. }
  961. Post_SOURCE_T2P (rhs_ct2p_t, rhs_ct2p_p){
  962. label = "2"
  963. }
  964. Post_TARGET_Place rhs_ct2p_p2 {
  965. label = "3"
  966. }
  967. Post_TARGET_Transition rhs_ct2p_t2 {
  968. label = "4"
  969. }
  970. Post_PlaceLink (rhs_ct2p_p, rhs_ct2p_p2){
  971. label = "5"
  972. }
  973. Post_TransitionLink (rhs_ct2p_t, rhs_ct2p_t2){
  974. label = "6"
  975. }
  976. Post_TARGET_T2P (rhs_ct2p_t2, rhs_ct2p_p2) {
  977. label = "7"
  978. action = $
  979. include "primitives.alh"
  980. include "modelling.alh"
  981. Void function action(host_model : Element, name : String, mapping : Element):
  982. instantiate_attribute(host_model, name, "weight", read_attribute(host_model, mapping["2"], "weight"))
  983. return!
  984. $
  985. }
  986. }
  987. }
  988. }
  989. OnSuccess (copy_places, copy_transitions) {}
  990. OnSuccess (copy_transitions, copy_P2T) {}
  991. OnSuccess (copy_P2T, copy_T2P) {}
  992. OnSuccess (copy_T2P, success) {}
  993. OnFailure (copy_places, copy_transitions) {}
  994. OnFailure (copy_transitions, copy_P2T) {}
  995. OnFailure (copy_P2T, copy_T2P) {}
  996. OnFailure (copy_T2P, success) {}
  997. Initial (schedule, copy_places) {}
  998. }
  999. export annotate to models/pn_annotate
  1000. """
  1001. schedule_model_print = \
  1002. """
  1003. import models/RAM_PetriNets_Runtime as RAM_PN_R
  1004. RAM_PN_R print {
  1005. Composite schedule {
  1006. {Contains} Success success {}
  1007. {Contains} ForAll print_tokens {
  1008. LHS {
  1009. Pre_Place {
  1010. label = "0"
  1011. }
  1012. }
  1013. RHS {
  1014. Post_Place {
  1015. label = "0"
  1016. action = $
  1017. include "primitives.alh"
  1018. include "modelling.alh"
  1019. Void function action(host_model : Element, name : String, mapping : Element):
  1020. output((cast_v2s(read_attribute(host_model, name, "name")) + " --> ") + cast_v2s(read_attribute(host_model, name, "tokens")))
  1021. return!
  1022. $
  1023. }
  1024. }
  1025. }
  1026. }
  1027. OnSuccess (print_tokens, success) {}
  1028. OnFailure (print_tokens, success) {}
  1029. Initial (schedule, print_tokens) {}
  1030. }
  1031. export print to models/pn_print
  1032. """
  1033. schedule_model_simulate = \
  1034. """
  1035. import models/RAM_PetriNets_Runtime as RAM_PN_R
  1036. RAM_PN_R s {
  1037. Composite schedule {
  1038. {Contains} Failure failure {}
  1039. {Contains} Success success {}
  1040. {Contains} Atomic mark {
  1041. LHS {
  1042. Pre_Transition {
  1043. label = "1"
  1044. constraint = $
  1045. include "primitives.alh"
  1046. include "modelling.alh"
  1047. include "object_operations.alh"
  1048. Boolean function constraint(host_model : Element, name : String):
  1049. Element links
  1050. String link
  1051. String place
  1052. links = allIncomingAssociationInstances(host_model, name, "P2T")
  1053. while (read_nr_out(links) > 0):
  1054. link = set_pop(links)
  1055. place = readAssociationSource(host_model, link)
  1056. if (integer_lt(read_attribute(host_model, place, "tokens"), read_attribute(host_model, link, "weight"))):
  1057. return False!
  1058. return True!
  1059. $
  1060. }
  1061. }
  1062. RHS {
  1063. Post_Transition {
  1064. label = "1"
  1065. action = $
  1066. include "primitives.alh"
  1067. include "modelling.alh"
  1068. Void function action(host_model : Element, name : String, mapping : Element):
  1069. unset_attribute(host_model, name, "executing")
  1070. instantiate_attribute(host_model, name, "executing", True)
  1071. return!
  1072. $
  1073. }
  1074. }
  1075. }
  1076. {Contains} ForAll consume {
  1077. LHS {
  1078. Pre_Transition lhs_consume_t{
  1079. label = "0"
  1080. constraint = $
  1081. include "primitives.alh"
  1082. include "modelling.alh"
  1083. Boolean function constraint(host_model : Element, name : String):
  1084. // Check if this node is executing currently
  1085. return value_eq(read_attribute(host_model, name, "executing"), True)!
  1086. $
  1087. }
  1088. Pre_Place lhs_consume_p{
  1089. label = "1"
  1090. }
  1091. Pre_P2T lhs_consume_p2t(lhs_consume_p, lhs_consume_t){
  1092. label = "2"
  1093. }
  1094. }
  1095. RHS {
  1096. Post_Transition rhs_consume_t {
  1097. label = "0"
  1098. }
  1099. Post_Place rhs_consume_p {
  1100. label = "1"
  1101. action = $
  1102. include "primitives.alh"
  1103. include "modelling.alh"
  1104. Void function action(host_model : Element, name : String, mapping : Element):
  1105. Integer tokens
  1106. Integer weight
  1107. tokens = read_attribute(host_model, name, "tokens")
  1108. weight = read_attribute(host_model, mapping["2"], "weight")
  1109. unset_attribute(host_model, name, "tokens")
  1110. instantiate_attribute(host_model, name, "tokens", tokens - weight)
  1111. return!
  1112. $
  1113. }
  1114. Post_P2T (rhs_consume_p, rhs_consume_t){
  1115. label = "2"
  1116. }
  1117. }
  1118. }
  1119. {Contains} ForAll produce {
  1120. LHS {
  1121. Pre_Transition lhs_produce_t{
  1122. label = "0"
  1123. constraint = $
  1124. include "primitives.alh"
  1125. include "modelling.alh"
  1126. Boolean function constraint(host_model : Element, name : String):
  1127. // Check if this node is executing currently
  1128. return value_eq(read_attribute(host_model, name, "executing"), True)!
  1129. $
  1130. }
  1131. Pre_Place lhs_produce_p{
  1132. label = "1"
  1133. }
  1134. Pre_T2P (lhs_produce_t, lhs_produce_p){
  1135. label = "2"
  1136. }
  1137. }
  1138. RHS {
  1139. Post_Transition rhs_produce_t{
  1140. label = "0"
  1141. }
  1142. Post_Place rhs_produce_p{
  1143. label = "1"
  1144. action = $
  1145. include "primitives.alh"
  1146. include "modelling.alh"
  1147. Void function action(host_model : Element, name : String, mapping : Element):
  1148. Integer tokens
  1149. Integer weight
  1150. tokens = read_attribute(host_model, name, "tokens")
  1151. weight = read_attribute(host_model, mapping["2"], "weight")
  1152. unset_attribute(host_model, name, "tokens")
  1153. instantiate_attribute(host_model, name, "tokens", tokens + weight)
  1154. return!
  1155. $
  1156. }
  1157. Post_T2P (rhs_produce_t, rhs_produce_p){
  1158. label = "2"
  1159. }
  1160. }
  1161. }
  1162. {Contains} Atomic unmark_transition {
  1163. LHS {
  1164. Pre_Transition {
  1165. label = "0"
  1166. constraint = $
  1167. include "primitives.alh"
  1168. include "modelling.alh"
  1169. Boolean function constraint(host_model : Element, name : String):
  1170. // Check if this node is executing currently
  1171. return value_eq(read_attribute(host_model, name, "executing"), True)!
  1172. $
  1173. }
  1174. }
  1175. RHS {
  1176. Post_Transition {
  1177. label = "0"
  1178. action = $
  1179. include "primitives.alh"
  1180. include "modelling.alh"
  1181. Void function action(host_model : Element, name : String, mapping : Element):
  1182. unset_attribute(host_model, name, "executing")
  1183. instantiate_attribute(host_model, name, "executing", False)
  1184. return!
  1185. $
  1186. }
  1187. }
  1188. }
  1189. }
  1190. OnSuccess (mark, consume) {}
  1191. OnFailure (mark, failure) {}
  1192. OnSuccess (consume, produce) {}
  1193. OnFailure (consume, produce) {}
  1194. OnSuccess (produce, unmark_transition) {}
  1195. OnFailure (produce, unmark_transition) {}
  1196. OnSuccess (unmark_transition, success) {}
  1197. OnFailure (unmark_transition, failure) {}
  1198. Initial (schedule, mark) {}
  1199. }
  1200. export s to models/pn_simulate
  1201. """
  1202. self.assertTrue(run_file(all_files,
  1203. get_model_constructor(PN_runtime) + \
  1204. get_model_constructor(PN_model) + [
  1205. "unify", "PetriNets_Design_to_Runtime", "PetriNets_Design", "SOURCE_", "PetriNets_Runtime", "TARGET_",
  1206. "join", "pn", "PetriNets_Design_to_Runtime", "SOURCE_",
  1207. "load", "PetriNets_Design_to_Runtime",
  1208. "instantiate", "Association", "PlaceLink", "SOURCE_Place", "TARGET_Place",
  1209. "instantiate", "Association", "TransitionLink", "SOURCE_Transition", "TARGET_Transition",
  1210. "exit",
  1211. "ramify", "RAM_PetriNets_Design_Runtime", "PetriNets_Design_to_Runtime",
  1212. "ramify", "RAM_PetriNets_Runtime", "PetriNets_Runtime",
  1213. ] + get_model_constructor(schedule_model_annotate) + [
  1214. ] + get_model_constructor(schedule_model_print) + [
  1215. ] + get_model_constructor(schedule_model_simulate) + [
  1216. "transform", "pn", "pn_annotate",
  1217. "split", "pn", "PetriNets_Runtime", "TARGET_",
  1218. "transform", "pn", "pn_print",
  1219. "transform", "pn", "pn_simulate",
  1220. "transform", "pn", "pn_print",
  1221. ],
  1222. greeting + prompt * 3 +
  1223. unify + prompt +
  1224. join + prompt +
  1225. load + loaded +
  1226. instantiate_edge + prompt +
  1227. instantiate_edge + prompt +
  1228. prompt +
  1229. ramify + prompt +
  1230. ramify + prompt +
  1231. prompt +
  1232. prompt +
  1233. prompt +
  1234. transform + transform_result_true + prompt +
  1235. split + prompt +
  1236. transform + [set(['"p1" --> 1', '"p2" --> 2', '"p3" --> 3'])] + transform_result_true + prompt +
  1237. transform + transform_result_true + prompt +
  1238. transform + [set(['"p1" --> 0', '"p2" --> 1', '"p3" --> 5'])] + transform_result_true + prompt
  1239. ,
  1240. "PO"))