test_pn_interface.py 60 KB

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