test_pn_interface.py 54 KB

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