test_pn_interface.py 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  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. None, "PO"))
  734. #greeting + prompt * 3 +
  735. # load + loaded +
  736. # read_node("t1", "Transition", [], [("executing", "Boolean", False)]) + prompt +
  737. # read_node("p1", "Place", [], [("tokens", "Natural", 1)]) + prompt +
  738. # read_node("p2", "Place", [], [("tokens", "Natural", 2)]) + prompt +
  739. # read_node("p3", "Place", [], [("tokens", "Natural", 3)]) + prompt +
  740. # prompt +
  741. # ramify + prompt +
  742. # prompt +
  743. # transform + transform_result_true + prompt +
  744. # load + loaded +
  745. # ["OK"] + prompt +
  746. # read_node("t1", "Transition", [], [("executing", "Boolean", False)]) + prompt +
  747. # read_node("p1", "Place", [], [("tokens", "Natural", 0)]) + prompt +
  748. # read_node("p2", "Place", [], [("tokens", "Natural", 1)]) + prompt +
  749. # read_node("p3", "Place", [], [("tokens", "Natural", 5)]) + prompt,
  750. #"PO"))
  751. def test_po_pn_interface_transform_pn_to_runtime(self):
  752. PN_runtime = \
  753. """
  754. import models/SimpleClassDiagrams as SimpleClassDiagrams
  755. SimpleClassDiagrams PetriNets_Design{
  756. Class Natural {}
  757. Class Place {
  758. tokens : Natural
  759. }
  760. Class Transition {}
  761. Association P2T (Place, Transition) {
  762. weight : Natural
  763. }
  764. Association T2P (Transition, Place) {
  765. weight : Natural
  766. }
  767. }
  768. SimpleClassDiagrams PetriNets_Runtime{
  769. Class Natural {}
  770. Class Boolean {}
  771. Class String {}
  772. Class Place {
  773. tokens : Natural
  774. name : String
  775. }
  776. Class Transition {
  777. executing : Boolean
  778. }
  779. Association P2T (Place, Transition) {
  780. weight : Natural
  781. }
  782. Association T2P (Transition, Place) {
  783. weight : Natural
  784. }
  785. }
  786. export PetriNets_Design to models/PetriNets_Design
  787. export PetriNets_Runtime to models/PetriNets_Runtime
  788. """
  789. PN_model = \
  790. """
  791. import models/PetriNets_Design as PetriNets
  792. PetriNets pn {
  793. Place p1 {
  794. tokens = 1
  795. }
  796. Place p2 {
  797. tokens = 2
  798. }
  799. Place p3 {
  800. tokens = 3
  801. }
  802. Transition t1 {}
  803. P2T (p1, t1) {
  804. weight = 1
  805. }
  806. P2T (p2, t1) {
  807. weight = 1
  808. }
  809. T2P (t1, p3) {
  810. weight = 2
  811. }
  812. }
  813. export pn to models/pn
  814. """
  815. schedule_model_annotate = \
  816. """
  817. import models/RAM_PetriNets_Design_Runtime as RAM_PN_DR
  818. RAM_PN_DR annotate {
  819. Composite schedule {
  820. {Contains} Failure failure {}
  821. {Contains} Success success {}
  822. {Contains} ForAll copy_transitions {
  823. LHS {
  824. Pre_SOURCE_Transition {
  825. label = "0"
  826. }
  827. }
  828. RHS {
  829. Post_SOURCE_Transition ct1 {
  830. label = "0"
  831. }
  832. Post_TARGET_Transition ct2 {
  833. label = "1"
  834. action = $
  835. include "primitives.alh"
  836. include "modelling.alh"
  837. Void function action(host_model : Element, name : String, mapping : Element):
  838. instantiate_attribute(host_model, name, "executing", False)
  839. return!
  840. $
  841. }
  842. Post_TransitionLink (ct1, ct2){
  843. label = "2"
  844. }
  845. }
  846. }
  847. {Contains} ForAll copy_places {
  848. LHS {
  849. Pre_SOURCE_Place {
  850. label = "0"
  851. }
  852. }
  853. RHS {
  854. Post_SOURCE_Place cp1 {
  855. label = "0"
  856. }
  857. Post_TARGET_Place cp2 {
  858. label = "1"
  859. action = $
  860. include "primitives.alh"
  861. include "modelling.alh"
  862. Void function action(host_model : Element, name : String, mapping : Element):
  863. instantiate_attribute(host_model, name, "tokens", read_attribute(host_model, mapping["0"], "tokens"))
  864. instantiate_attribute(host_model, name, "name", mapping["0"])
  865. return!
  866. $
  867. }
  868. Post_PlaceLink (cp1, cp2){
  869. label = "2"
  870. }
  871. }
  872. }
  873. {Contains} ForAll copy_P2T {
  874. LHS {
  875. Pre_SOURCE_Place cp2t_p{
  876. label = "0"
  877. }
  878. Pre_SOURCE_Transition cp2t_t{
  879. label = "1"
  880. }
  881. Pre_SOURCE_P2T (cp2t_p, cp2t_t){
  882. label = "2"
  883. }
  884. Pre_TARGET_Place cp2t_p2{
  885. label = "3"
  886. }
  887. Pre_TARGET_Transition cp2t_t2{
  888. label = "4"
  889. }
  890. Pre_PlaceLink (cp2t_p, cp2t_p2){
  891. label = "5"
  892. }
  893. Pre_TransitionLink (cp2t_t, cp2t_t2){
  894. label = "6"
  895. }
  896. }
  897. RHS {
  898. Post_SOURCE_Place rhs_cp2t_p{
  899. label = "0"
  900. }
  901. Post_SOURCE_Transition rhs_cp2t_t{
  902. label = "1"
  903. }
  904. Post_SOURCE_P2T rhs_cp2t_p2t (rhs_cp2t_p, rhs_cp2t_t){
  905. label = "2"
  906. }
  907. Post_TARGET_Place rhs_cp2t_p2 {
  908. label = "3"
  909. }
  910. Post_TARGET_Transition rhs_cp2t_t2 {
  911. label = "4"
  912. }
  913. Post_PlaceLink (rhs_cp2t_p, rhs_cp2t_p2){
  914. label = "5"
  915. }
  916. Post_TransitionLink (rhs_cp2t_t, rhs_cp2t_t2){
  917. label = "6"
  918. }
  919. Post_TARGET_P2T rhs_cp2t_p2t2(rhs_cp2t_p2, rhs_cp2t_t2) {
  920. label = "7"
  921. action = $
  922. include "primitives.alh"
  923. include "modelling.alh"
  924. Void function action(host_model : Element, name : String, mapping : Element):
  925. instantiate_attribute(host_model, name, "weight", read_attribute(host_model, mapping["2"], "weight"))
  926. return!
  927. $
  928. }
  929. }
  930. }
  931. {Contains} ForAll copy_T2P {
  932. LHS {
  933. Pre_SOURCE_Place ct2p_p{
  934. label = "0"
  935. }
  936. Pre_SOURCE_Transition ct2p_t{
  937. label = "1"
  938. }
  939. Pre_SOURCE_T2P (ct2p_t, ct2p_p){
  940. label = "2"
  941. }
  942. Pre_TARGET_Place ct2p_p2{
  943. label = "3"
  944. }
  945. Pre_TARGET_Transition ct2p_t2{
  946. label = "4"
  947. }
  948. Pre_PlaceLink (ct2p_p, ct2p_p2){
  949. label = "5"
  950. }
  951. Pre_TransitionLink (ct2p_t, ct2p_t2){
  952. label = "6"
  953. }
  954. }
  955. RHS {
  956. Post_SOURCE_Place rhs_ct2p_p{
  957. label = "0"
  958. }
  959. Post_SOURCE_Transition rhs_ct2p_t{
  960. label = "1"
  961. }
  962. Post_SOURCE_T2P (rhs_ct2p_t, rhs_ct2p_p){
  963. label = "2"
  964. }
  965. Post_TARGET_Place rhs_ct2p_p2 {
  966. label = "3"
  967. }
  968. Post_TARGET_Transition rhs_ct2p_t2 {
  969. label = "4"
  970. }
  971. Post_PlaceLink (rhs_ct2p_p, rhs_ct2p_p2){
  972. label = "5"
  973. }
  974. Post_TransitionLink (rhs_ct2p_t, rhs_ct2p_t2){
  975. label = "6"
  976. }
  977. Post_TARGET_T2P (rhs_ct2p_t2, rhs_ct2p_p2) {
  978. label = "7"
  979. action = $
  980. include "primitives.alh"
  981. include "modelling.alh"
  982. Void function action(host_model : Element, name : String, mapping : Element):
  983. instantiate_attribute(host_model, name, "weight", read_attribute(host_model, mapping["2"], "weight"))
  984. return!
  985. $
  986. }
  987. }
  988. }
  989. }
  990. OnSuccess (copy_places, copy_transitions) {}
  991. OnSuccess (copy_transitions, copy_P2T) {}
  992. OnSuccess (copy_P2T, copy_T2P) {}
  993. OnSuccess (copy_T2P, success) {}
  994. OnFailure (copy_places, copy_transitions) {}
  995. OnFailure (copy_transitions, copy_P2T) {}
  996. OnFailure (copy_P2T, copy_T2P) {}
  997. OnFailure (copy_T2P, success) {}
  998. Initial (schedule, copy_places) {}
  999. }
  1000. export annotate to models/pn_annotate
  1001. """
  1002. schedule_model_print = \
  1003. """
  1004. import models/RAM_PetriNets_Runtime as RAM_PN_R
  1005. RAM_PN_R print {
  1006. Composite schedule {
  1007. {Contains} Success success {}
  1008. {Contains} ForAll print_tokens {
  1009. LHS {
  1010. Pre_Place {
  1011. label = "0"
  1012. }
  1013. }
  1014. RHS {
  1015. Post_Place {
  1016. label = "0"
  1017. action = $
  1018. include "primitives.alh"
  1019. include "modelling.alh"
  1020. Void function action(host_model : Element, name : String, mapping : Element):
  1021. output((cast_v2s(read_attribute(host_model, name, "name")) + " --> ") + cast_v2s(read_attribute(host_model, name, "tokens")))
  1022. return!
  1023. $
  1024. }
  1025. }
  1026. }
  1027. }
  1028. OnSuccess (print_tokens, success) {}
  1029. OnFailure (print_tokens, success) {}
  1030. Initial (schedule, print_tokens) {}
  1031. }
  1032. export print to models/pn_print
  1033. """
  1034. schedule_model_simulate = \
  1035. """
  1036. import models/RAM_PetriNets_Runtime as RAM_PN_R
  1037. RAM_PN_R s {
  1038. Composite schedule {
  1039. {Contains} Failure failure {}
  1040. {Contains} Success success {}
  1041. {Contains} Atomic mark {
  1042. LHS {
  1043. Pre_Transition {
  1044. label = "1"
  1045. constraint = $
  1046. include "primitives.alh"
  1047. include "modelling.alh"
  1048. include "object_operations.alh"
  1049. Boolean function constraint(host_model : Element, name : String):
  1050. Element links
  1051. String link
  1052. String place
  1053. links = allIncomingAssociationInstances(host_model, name, "P2T")
  1054. while (read_nr_out(links) > 0):
  1055. link = set_pop(links)
  1056. place = readAssociationSource(host_model, link)
  1057. if (integer_lt(read_attribute(host_model, place, "tokens"), read_attribute(host_model, link, "weight"))):
  1058. return False!
  1059. return True!
  1060. $
  1061. }
  1062. }
  1063. RHS {
  1064. Post_Transition {
  1065. label = "1"
  1066. action = $
  1067. include "primitives.alh"
  1068. include "modelling.alh"
  1069. Void function action(host_model : Element, name : String, mapping : Element):
  1070. unset_attribute(host_model, name, "executing")
  1071. instantiate_attribute(host_model, name, "executing", True)
  1072. return!
  1073. $
  1074. }
  1075. }
  1076. }
  1077. {Contains} ForAll consume {
  1078. LHS {
  1079. Pre_Transition lhs_consume_t{
  1080. label = "0"
  1081. constraint = $
  1082. include "primitives.alh"
  1083. include "modelling.alh"
  1084. Boolean function constraint(host_model : Element, name : String):
  1085. // Check if this node is executing currently
  1086. return value_eq(read_attribute(host_model, name, "executing"), True)!
  1087. $
  1088. }
  1089. Pre_Place lhs_consume_p{
  1090. label = "1"
  1091. }
  1092. Pre_P2T lhs_consume_p2t(lhs_consume_p, lhs_consume_t){
  1093. label = "2"
  1094. }
  1095. }
  1096. RHS {
  1097. Post_Transition rhs_consume_t {
  1098. label = "0"
  1099. }
  1100. Post_Place rhs_consume_p {
  1101. label = "1"
  1102. action = $
  1103. include "primitives.alh"
  1104. include "modelling.alh"
  1105. Void function action(host_model : Element, name : String, mapping : Element):
  1106. Integer tokens
  1107. Integer weight
  1108. tokens = read_attribute(host_model, name, "tokens")
  1109. weight = read_attribute(host_model, mapping["2"], "weight")
  1110. unset_attribute(host_model, name, "tokens")
  1111. instantiate_attribute(host_model, name, "tokens", tokens - weight)
  1112. log("Consume for " + cast_v2s(read_attribute(host_model, name, "name")))
  1113. log("Previous: " + cast_v2s(tokens))
  1114. log("Now: " + cast_v2s(tokens - weight))
  1115. return!
  1116. $
  1117. }
  1118. Post_P2T (rhs_consume_p, rhs_consume_t){
  1119. label = "2"
  1120. }
  1121. }
  1122. }
  1123. {Contains} ForAll produce {
  1124. LHS {
  1125. Pre_Transition lhs_produce_t{
  1126. label = "0"
  1127. constraint = $
  1128. include "primitives.alh"
  1129. include "modelling.alh"
  1130. Boolean function constraint(host_model : Element, name : String):
  1131. // Check if this node is executing currently
  1132. return value_eq(read_attribute(host_model, name, "executing"), True)!
  1133. $
  1134. }
  1135. Pre_Place lhs_produce_p{
  1136. label = "1"
  1137. }
  1138. Pre_T2P (lhs_produce_t, lhs_produce_p){
  1139. label = "2"
  1140. }
  1141. }
  1142. RHS {
  1143. Post_Transition rhs_produce_t{
  1144. label = "0"
  1145. }
  1146. Post_Place rhs_produce_p{
  1147. label = "1"
  1148. action = $
  1149. include "primitives.alh"
  1150. include "modelling.alh"
  1151. Void function action(host_model : Element, name : String, mapping : Element):
  1152. Integer tokens
  1153. Integer weight
  1154. tokens = read_attribute(host_model, name, "tokens")
  1155. weight = read_attribute(host_model, mapping["2"], "weight")
  1156. unset_attribute(host_model, name, "tokens")
  1157. instantiate_attribute(host_model, name, "tokens", tokens + weight)
  1158. log("Produce for " + cast_v2s(read_attribute(host_model, name, "name")))
  1159. log("Previous: " + cast_v2s(tokens))
  1160. log("Now: " + cast_v2s(tokens + weight))
  1161. return!
  1162. $
  1163. }
  1164. Post_T2P (rhs_produce_t, rhs_produce_p){
  1165. label = "2"
  1166. }
  1167. }
  1168. }
  1169. {Contains} Atomic unmark_transition {
  1170. LHS {
  1171. Pre_Transition {
  1172. label = "0"
  1173. constraint = $
  1174. include "primitives.alh"
  1175. include "modelling.alh"
  1176. Boolean function constraint(host_model : Element, name : String):
  1177. // Check if this node is executing currently
  1178. return value_eq(read_attribute(host_model, name, "executing"), True)!
  1179. $
  1180. }
  1181. }
  1182. RHS {
  1183. Post_Transition {
  1184. label = "0"
  1185. action = $
  1186. include "primitives.alh"
  1187. include "modelling.alh"
  1188. Void function action(host_model : Element, name : String, mapping : Element):
  1189. unset_attribute(host_model, name, "executing")
  1190. instantiate_attribute(host_model, name, "executing", False)
  1191. return!
  1192. $
  1193. }
  1194. }
  1195. }
  1196. }
  1197. OnSuccess (mark, consume) {}
  1198. OnFailure (mark, failure) {}
  1199. OnSuccess (consume, produce) {}
  1200. OnFailure (consume, produce) {}
  1201. OnSuccess (produce, unmark_transition) {}
  1202. OnFailure (produce, unmark_transition) {}
  1203. OnSuccess (unmark_transition, success) {}
  1204. OnFailure (unmark_transition, failure) {}
  1205. Initial (schedule, mark) {}
  1206. }
  1207. export s to models/pn_simulate
  1208. """
  1209. self.assertTrue(run_file(all_files,
  1210. get_model_constructor(PN_runtime) + \
  1211. get_model_constructor(PN_model) + [
  1212. "unify", "PetriNets_Design_to_Runtime", "PetriNets_Design", "SOURCE_", "PetriNets_Runtime", "TARGET_",
  1213. "join", "pn", "PetriNets_Design_to_Runtime", "SOURCE_",
  1214. "load", "PetriNets_Design_to_Runtime",
  1215. "instantiate", "Association", "PlaceLink", "SOURCE_Place", "TARGET_Place",
  1216. "instantiate", "Association", "TransitionLink", "SOURCE_Transition", "TARGET_Transition",
  1217. "exit",
  1218. "ramify", "RAM_PetriNets_Design_Runtime", "PetriNets_Design_to_Runtime",
  1219. "ramify", "RAM_PetriNets_Runtime", "PetriNets_Runtime",
  1220. ] + get_model_constructor(schedule_model_annotate) + [
  1221. ] + get_model_constructor(schedule_model_print) + [
  1222. ] + get_model_constructor(schedule_model_simulate) + [
  1223. "transform", "pn", "pn_annotate",
  1224. "split", "pn", "PetriNets_Runtime", "TARGET_",
  1225. "transform", "pn", "pn_print",
  1226. "transform", "pn", "pn_simulate",
  1227. "transform", "pn", "pn_print",
  1228. ],
  1229. #greeting + prompt * 3 +
  1230. # unify + prompt +
  1231. # join + prompt +
  1232. # load + loaded +
  1233. # instantiate_edge + prompt +
  1234. # instantiate_edge + prompt +
  1235. # prompt +
  1236. # ramify + prompt +
  1237. # ramify + prompt +
  1238. # prompt +
  1239. # prompt +
  1240. # prompt +
  1241. # transform + transform_result_true + prompt +
  1242. # split + prompt +
  1243. # transform + [set(['"p1" --> 1', '"p2" --> 2', '"p3" --> 3'])] + transform_result_true + prompt +
  1244. # transform + transform_result_true + prompt +
  1245. # transform + [set(['"p1" --> 0', '"p2" --> 1', '"p3" --> 5'])] + transform_result_true + prompt
  1246. # ,
  1247. #"PO"))
  1248. None, "PO"))