test_pn_interface.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. import unittest
  2. from utils import run_file, get_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. "constructors.alc",
  31. "modelling.alc",
  32. "compilation_manager.alc",
  33. ]
  34. greeting = ["Welcome to the Model Management Interface, running live on the Modelverse!",
  35. "Use 'help' command for a list of possible commands"]
  36. new = ["Metamodel to instantiate?",
  37. "Name of model?"]
  38. prompt = ["Please give your command."]
  39. loaded = ["Model loaded, ready for commands!",
  40. "Use 'help' command for a list of possible commands"] + prompt
  41. load = ["Model to load?"]
  42. instantiate = ["Type to instantiate?"]
  43. instantiate_name = ["Name of new element?"]
  44. instantiate_ok = ["Instantiation successful!"]
  45. instantiate_source= ["Source name?"]
  46. instantiate_destination = ["Destination name?"]
  47. def list_menu(defined):
  48. defined.append(("PetriNets", "SimpleClassDiagrams"))
  49. defined.append(("SimpleClassDiagrams", "SimpleClassDiagrams"))
  50. defined.append(("LTM_bottom", "LTM_bottom"))
  51. return ["Found models:",
  52. set([" %s : %s" % (m, mm) for m, mm in defined])]
  53. def list_model(defined):
  54. return ["List of all elements:",
  55. set([" %s : %s" % (m, mm) for m, mm in defined])]
  56. def read_node(name, t, defs, attrs):
  57. return ["Element to read?",
  58. "Name: %s" % name,
  59. "Type: %s" % t,
  60. "Defines attributes:"] + \
  61. ([set([" %s : %s" % (m, mm) for m, mm in defs])] if defs else []) + \
  62. ["Attributes:"] + \
  63. ([set([' "%s" : "%s" = %s' % (m, mm, v) for m, mm, v in attrs])] if attrs else [])
  64. def read_edge(name, t, src, dst, defs, attrs):
  65. return ["Element to read?",
  66. "Name: %s" % name,
  67. "Type: %s" % t,
  68. "Source: %s" % src,
  69. "Destination: %s" % dst,
  70. "Defines attributes:"] + \
  71. ([set([" %s : %s" % (m, mm) for m, mm in defs])] if defs else []) + \
  72. ["Attributes:"] + \
  73. ([set([' "%s" : "%s" = %s' % (m, mm, v) for m, mm, v in attrs])] if attrs else [])
  74. delete = ["Model to delete?", "Deleted!"]
  75. rename = ["Old name?", "New name?", "Rename complete!"]
  76. attr_add = ["Which model do you want to assign an attribute to?",
  77. "Which attribute do you wish to assign?",
  78. "Value of attribute?",
  79. "Added attribute!"]
  80. attr_del = ["Which model do you want to remove an attribute of?",
  81. "Which attribute do you want to delete?",
  82. "Attribute deleted!",
  83. ]
  84. help_root = ["Currently no model is loaded, so your operations are limited to:",
  85. " new -- Create a new model and save it for future use"
  86. " load -- Load a previously made model",
  87. " rename -- Rename a previously made model",
  88. " delete -- Delete a previously made model",
  89. " list -- Show a list of all stored models",
  90. " help -- Show a list of possible commands"]
  91. verify_fail_weight= ["Natural number not larger than or equal to zero"]
  92. verify_fail_tokens= ["Natural number not larger than or equal to zero"]
  93. verify_fail_structure = ["Source of model edge not typed by source of type: p2t"]
  94. init = greeting + prompt
  95. did_instantiate_simple = init + \
  96. new + \
  97. loaded +\
  98. instantiate_node + \
  99. prompt + \
  100. instantiate_node + \
  101. prompt + \
  102. attr_add + \
  103. prompt + \
  104. instantiate_node + \
  105. prompt + \
  106. attr_add + \
  107. prompt + \
  108. instantiate_edge + \
  109. prompt + \
  110. attr_add + \
  111. prompt + \
  112. instantiate_edge + \
  113. prompt + \
  114. attr_add + \
  115. prompt
  116. def list_types(t):
  117. return ["List of types:"] + \
  118. [set([" %s : %s" % (m, mm) for m, mm in t])]
  119. modify = ["Element to modify?",
  120. "Attribute to modify?",
  121. "New value?",
  122. "Modified!",]
  123. class TestPetrinetInterface(unittest.TestCase):
  124. def test_po_pn_interface_manage(self):
  125. self.pn_interface_manage("PO")
  126. def test_co_pn_interface_manage(self):
  127. self.pn_interface_manage("CO")
  128. def pn_interface_manage(self, mode):
  129. self.assertTrue(run_file(all_files,
  130. ["list",
  131. "new", "PetriNets", "abc", "exit",
  132. "list",
  133. "new", "PetriNets", "def", "exit",
  134. "list",
  135. "delete", "def",
  136. "list",
  137. "rename", "abc", "a",
  138. "list",
  139. "delete", "a",
  140. "list",
  141. ],
  142. init + \
  143. list_menu([]) + prompt + \
  144. new + loaded + prompt + list_menu([("abc", "PetriNets")]) + prompt + \
  145. new + loaded + prompt + list_menu([("abc", "PetriNets"), ("def", "PetriNets")]) + prompt + \
  146. delete + prompt + list_menu([("abc", "PetriNets")]) + prompt + \
  147. rename + prompt + list_menu([("a", "PetriNets")]) + prompt + \
  148. delete + prompt + list_menu([]) + prompt,
  149. mode))
  150. def test_po_pn_interface_new_reload(self):
  151. self.pn_interface_new_reload("PO")
  152. def test_co_pn_interface_new_reload(self):
  153. self.pn_interface_new_reload("CO")
  154. def pn_interface_new_reload(self, mode):
  155. self.assertTrue(run_file(all_files,
  156. ["new", "PetriNets", "abc", "exit", "load", "abc"],
  157. init + new + loaded + prompt + load + loaded,
  158. mode))
  159. def test_po_pn_interface_instantiate_place(self):
  160. self.pn_interface_instantiate_place("PO")
  161. def test_co_pn_interface_instantiate_place(self):
  162. self.pn_interface_instantiate_place("CO")
  163. def pn_interface_instantiate_place(self, mode):
  164. self.assertTrue(run_file(all_files,
  165. ["new", "PetriNets", "abc",
  166. "instantiate", "Place", "p1",
  167. "attr_add", "p1", "tokens", 5,
  168. "list",
  169. "read", "p1",
  170. "instantiate", "Transition", "t1",
  171. "list",
  172. "read", "t1"],
  173. init + new + loaded + \
  174. instantiate_node + prompt + \
  175. attr_add + prompt + \
  176. list_model([("p1", "Place"), ("p1.tokens", "Natural")]) + prompt + \
  177. read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
  178. instantiate_node + prompt + \
  179. list_model([("p1", "Place"), ("t1", "Transition"), ("p1.tokens", "Natural")]) + prompt + \
  180. read_node("t1", "Transition", [], []) + prompt,
  181. mode))
  182. def test_po_pn_interface_instantiate_arcs(self):
  183. self.pn_interface_instantiate_arcs("PO")
  184. def test_co_pn_interface_instantiate_arcs(self):
  185. self.pn_interface_instantiate_arcs("CO")
  186. def pn_interface_instantiate_arcs(self, mode):
  187. self.assertTrue(run_file(all_files,
  188. do_instantiate_simple + [
  189. "read", "p1",
  190. "read", "p2",
  191. "read", "t1",
  192. "read", "p2t",
  193. "read", "t2p",
  194. ],
  195. did_instantiate_simple + \
  196. read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
  197. read_node("p2", "Place", [], [("tokens", "Natural", 0)]) + prompt + \
  198. read_node("t1", "Transition", [], []) + prompt + \
  199. read_edge("p2t", "P2T", "p1", "t1", [], [("weight", "Natural", 2)]) + prompt + \
  200. read_edge("t2p", "T2P", "t1", "p2", [], [("weight", "Natural", 1)]) + prompt,
  201. mode))
  202. def test_po_pn_interface_verify_OK(self):
  203. self.pn_interface_verify_OK("PO")
  204. def test_co_pn_interface_verify_OK(self):
  205. self.pn_interface_verify_OK("CO")
  206. def pn_interface_verify_OK(self, mode):
  207. self.assertTrue(run_file(all_files,
  208. do_instantiate_simple + ["verify"],
  209. did_instantiate_simple + ["OK"], mode))
  210. def test_po_pn_interface_verify_fail_tokens(self):
  211. self.pn_interface_verify_fail_tokens("PO")
  212. def test_co_pn_interface_verify_fail_tokens(self):
  213. self.pn_interface_verify_fail_tokens("CO")
  214. def pn_interface_verify_fail_tokens(self, mode):
  215. self.assertTrue(run_file(all_files,
  216. do_instantiate_simple + ["modify", "p1", "tokens", -5, "verify"],
  217. did_instantiate_simple + modify + prompt + verify_fail_tokens + prompt, mode))
  218. def test_po_pn_interface_verify_fail_weight(self):
  219. self.pn_interface_verify_fail_weight("PO")
  220. def test_co_pn_interface_verify_fail_weight(self):
  221. self.pn_interface_verify_fail_weight("CO")
  222. def pn_interface_verify_fail_weight(self, mode):
  223. self.assertTrue(run_file(all_files,
  224. do_instantiate_simple + ["modify", "p2t", "weight", -2, "verify"],
  225. did_instantiate_simple + modify + prompt + verify_fail_weight + prompt, mode))
  226. def test_po_pn_interface_verify_fail_structure(self):
  227. self.pn_interface_verify_fail_structure("PO")
  228. def test_co_pn_interface_verify_fail_structure(self):
  229. self.pn_interface_verify_fail_structure("CO")
  230. def pn_interface_verify_fail_structure(self, mode):
  231. self.assertTrue(run_file(all_files,
  232. ["new", "PetriNets", "abc",
  233. "instantiate", "Transition", "t1",
  234. "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
  235. "instantiate", "P2T", "p2t", "t1", "p1", "attr_add", "p2t", "weight", 2, "verify"],
  236. init + new + loaded + \
  237. instantiate_node + prompt + \
  238. instantiate_node + prompt + attr_add + prompt + \
  239. instantiate_edge + prompt + attr_add + prompt + \
  240. verify_fail_structure,
  241. mode))
  242. def test_po_pn_interface_types(self):
  243. self.pn_interface_types("PO")
  244. def test_co_pn_interface_types(self):
  245. self.pn_interface_types("CO")
  246. def pn_interface_types(self, mode):
  247. self.assertTrue(run_file(all_files,
  248. ["new", "PetriNets", "abc", "types"],
  249. init + new + loaded + list_types([("Place", "Class"),
  250. ("Transition", "Class"),
  251. ("P2T", "Association"),
  252. ("T2P", "Association"),
  253. ("Natural", "Class"),
  254. ("Place_tokens", "Association"),
  255. ("Place_tokens.name", "String"),
  256. ("Place_tokens.target_lower_cardinality", "Natural"),
  257. ("Place_tokens.target_upper_cardinality", "Natural"),
  258. ("P2T_weight", "Association"),
  259. ("P2T_weight.name", "String"),
  260. ("P2T_weight.target_lower_cardinality", "Natural"),
  261. ("P2T_weight.target_upper_cardinality", "Natural"),
  262. ("T2P_weight", "Association"),
  263. ("T2P_weight.name", "String"),
  264. ("T2P_weight.target_lower_cardinality", "Natural"),
  265. ("T2P_weight.target_upper_cardinality", "Natural"),
  266. ]) + prompt,
  267. mode))
  268. def test_po_pn_interface_modify_place(self):
  269. self.pn_interface_modify_place("PO")
  270. def test_co_pn_interface_modify_place(self):
  271. self.pn_interface_modify_place("CO")
  272. def pn_interface_modify_place(self, mode):
  273. self.assertTrue(run_file(all_files,
  274. ["new", "PetriNets", "abc",
  275. "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
  276. "read", "p1",
  277. "modify", "p1", "tokens", 1, "read", "p1"],
  278. init + new + loaded + \
  279. instantiate_node + prompt + attr_add + prompt + \
  280. read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
  281. modify + prompt + \
  282. read_node("p1", "Place", [], [("tokens", "Natural", 1)]) + prompt,
  283. mode))
  284. def test_po_pn_interface_verify_fail_attr_lower_cardinality(self):
  285. self.pn_interface_verify_fail_attr_lower_cardinality("PO")
  286. def test_co_pn_interface_verify_fail_attr_lower_cardinality(self):
  287. self.pn_interface_verify_fail_attr_lower_cardinality("CO")
  288. def pn_interface_verify_fail_attr_lower_cardinality(self, mode):
  289. self.assertTrue(run_file(all_files,
  290. do_instantiate_simple + ["instantiate", "Place", "p999", "verify"],
  291. did_instantiate_simple + instantiate_node + prompt + ["Lower cardinality violation for outgoing edge of type Place_tokens at p999"] + prompt,
  292. mode))
  293. def test_po_pn_interface_verify_fail_attr_upper_cardinality(self):
  294. self.pn_interface_verify_fail_attr_upper_cardinality("PO")
  295. def test_co_pn_interface_verify_fail_attr_upper_cardinality(self):
  296. self.pn_interface_verify_fail_attr_upper_cardinality("CO")
  297. def pn_interface_verify_fail_attr_upper_cardinality(self, mode):
  298. self.assertTrue(run_file(all_files,
  299. do_instantiate_simple + ["attr_add", "p1", "tokens", 5, "verify"],
  300. did_instantiate_simple + attr_add + prompt + ["Upper cardinality violation for outgoing edge of type Place_tokens at p1"] + prompt,
  301. mode))
  302. def test_po_pn_interface_verify_natural(self):
  303. self.pn_interface_verify_natural("PO")
  304. def test_co_pn_interface_verify_natural(self):
  305. self.pn_interface_verify_natural("CO")
  306. def pn_interface_verify_natural(self, mode):
  307. self.assertTrue(run_file(all_files,
  308. ["new", "PetriNets", "abc",
  309. "instantiate", "Place", "p1",
  310. "attr_add", "p1", "tokens", -5,
  311. "attr_del", "p1", "tokens",
  312. "attr_add", "p1", "tokens", 4,
  313. "verify"],
  314. init + new + loaded + \
  315. instantiate_node + prompt + \
  316. attr_add + prompt + \
  317. attr_del + prompt + \
  318. attr_add + prompt + \
  319. ["OK"] + prompt,
  320. mode))
  321. def test_po_pn_interface_verify_PN_OK(self):
  322. self.pn_interface_verify_PN_OK("PO")
  323. def test_co_pn_interface_verify_PN_OK(self):
  324. self.pn_interface_verify_PN_OK("CO")
  325. def pn_interface_verify_PN_OK(self, mode):
  326. self.assertTrue(run_file(all_files,
  327. ["load", "PetriNets", "verify"],
  328. init + load + loaded + ["OK"], mode))
  329. def test_po_rpgame(self):
  330. self.rpgame("PO")
  331. def test_co_rpgame(self):
  332. self.rpgame("CO")
  333. def rpgame(self, mode):
  334. constraint_code = \
  335. """
  336. include "primitives.alh"
  337. include "object_operations.alh"
  338. Element function constraint(model : Element, name : String):
  339. \tElement associations
  340. \tElement back_associations
  341. \tElement association
  342. \tString destination
  343. \tassociations = allOutgoingAssociationInstances(model, name, "tile_left")
  344. \twhile (0 < list_len(associations)):
  345. \t\tassociation = set_pop(associations)
  346. \t\tdestination = readAssociationDestination(model, association)
  347. \t\tback_associations = allOutgoingAssociationInstances(model, destination, "tile_right")
  348. \t\tif (list_len(back_associations) < 1):
  349. \t\t\treturn "Left link does not have a right link back"!
  350. \t\telse:
  351. \t\t\tassociation = set_pop(back_associations)
  352. \t\t\tdestination = readAssociationDestination(model, association)
  353. \t\t\tif (destination != name):
  354. \t\t\t\treturn "Right link does not have a left link back to the same tile"!
  355. \tassociations = allOutgoingAssociationInstances(model, name, "tile_right")
  356. \twhile (0 < list_len(associations)):
  357. \t\tassociation = set_pop(associations)
  358. \t\tdestination = readAssociationDestination(model, association)
  359. \t\tback_associations = allOutgoingAssociationInstances(model, destination, "tile_left")
  360. \t\tif (list_len(back_associations) < 1):
  361. \t\t\treturn "Right link does not have a left link back"!
  362. \t\telse:
  363. \t\t\tassociation = set_pop(back_associations)
  364. \t\t\tdestination = readAssociationDestination(model, association)
  365. \t\t\tif (destination != name):
  366. \t\t\t\treturn "Right link does not have a left link back to the same tile"!
  367. \tassociations = allOutgoingAssociationInstances(model, name, "tile_top")
  368. \twhile (0 < list_len(associations)):
  369. \t\tassociation = set_pop(associations)
  370. \t\tdestination = readAssociationDestination(model, association)
  371. \t\tback_associations = allOutgoingAssociationInstances(model, destination, "tile_bottom")
  372. \t\tif (list_len(back_associations) < 1):
  373. \t\t\treturn "Top link does not have a bottom link back"!
  374. \t\telse:
  375. \t\t\tassociation = set_pop(back_associations)
  376. \t\t\tdestination = readAssociationDestination(model, association)
  377. \t\t\tif (destination != name):
  378. \t\t\t\treturn "Top link does not have a bottom link back to the same tile"!
  379. \tassociations = allOutgoingAssociationInstances(model, name, "tile_bottom")
  380. \twhile (0 < list_len(associations)):
  381. \t\tassociation = set_pop(associations)
  382. \t\tdestination = readAssociationDestination(model, association)
  383. \t\tback_associations = allOutgoingAssociationInstances(model, destination, "tile_top")
  384. \t\tif (list_len(back_associations) < 1):
  385. \t\t\treturn "Bottom link does not have a top link back"!
  386. \t\telse:
  387. \t\t\tassociation = set_pop(back_associations)
  388. \t\t\tdestination = readAssociationDestination(model, association)
  389. \t\t\tif (destination != name):
  390. \t\t\t\treturn "Bottom link does not have a top link back to the same tile"!
  391. \treturn "OK"!
  392. """
  393. constructors = get_constructor(constraint_code)
  394. self.assertTrue(run_file(all_files,
  395. ["new", "SimpleClassDiagrams", "RPGame",
  396. "set_inheritance", "Inheritance",
  397. "instantiate", "Class", "Scene",
  398. "instantiate", "Class", "Tile",
  399. "instantiate", "Class", "Item",
  400. "instantiate", "Class", "Goal",
  401. "instantiate", "Class", "Character",
  402. "instantiate", "Class", "Hero",
  403. "instantiate", "Association", "scene_has_tiles", "Scene", "Tile",
  404. "instantiate", "Association", "tile_left", "Tile", "Tile",
  405. "instantiate", "Association", "tile_right", "Tile", "Tile",
  406. "instantiate", "Association", "tile_top", "Tile", "Tile",
  407. "instantiate", "Association", "tile_bottom", "Tile", "Tile",
  408. "instantiate", "Association", "character_on", "Character", "Tile",
  409. "instantiate", "Association", "item_on", "Item", "Tile",
  410. "instantiate", "Inheritance", "hero_is_character", "Hero", "Character",
  411. "instantiate", "Inheritance", "goal_is_item", "Goal", "Item",
  412. "attr_add", "Scene", "lower_cardinality", 1,
  413. "attr_add", "Scene", "upper_cardinality", 1,
  414. "attr_add", "Goal", "lower_cardinality", 1,
  415. "attr_add", "scene_has_tiles", "source_lower_cardinality", 1,
  416. "attr_add", "scene_has_tiles", "source_upper_cardinality", 1,
  417. "attr_add", "scene_has_tiles", "target_lower_cardinality", 1,
  418. "attr_add", "item_on", "target_lower_cardinality", 1,
  419. "attr_add", "item_on", "target_upper_cardinality", 1,
  420. "attr_add", "item_on", "source_upper_cardinality", 1,
  421. "attr_add", "character_on", "target_lower_cardinality", 1,
  422. "attr_add", "character_on", "target_upper_cardinality", 1,
  423. "attr_add", "character_on", "source_upper_cardinality", 1,
  424. "attr_add", "tile_left", "source_upper_cardinality", 1,
  425. "attr_add", "tile_left", "target_upper_cardinality", 1,
  426. "attr_add", "tile_right", "source_upper_cardinality", 1,
  427. "attr_add", "tile_right", "target_upper_cardinality", 1,
  428. "attr_add", "tile_top", "source_upper_cardinality", 1,
  429. "attr_add", "tile_top", "target_upper_cardinality", 1,
  430. "attr_add", "tile_bottom", "source_upper_cardinality", 1,
  431. "attr_add", "tile_bottom", "target_upper_cardinality", 1,
  432. "attr_add_code", "Tile", "constraint",
  433. ] + constructors + ["verify"] + ["exit"] + [
  434. "new", "RPGame", "my_game",
  435. "instantiate", "Scene", "scene",
  436. "instantiate", "Hero", "Link",
  437. "instantiate", "Goal", "goal",
  438. "instantiate", "Tile", "tile_00",
  439. "instantiate", "Tile", "tile_01",
  440. "instantiate", "Tile", "tile_10",
  441. "instantiate", "Tile", "tile_11",
  442. "instantiate", "scene_has_tiles", "", "scene", "tile_00",
  443. "instantiate", "scene_has_tiles", "", "scene", "tile_01",
  444. "instantiate", "scene_has_tiles", "", "scene", "tile_10",
  445. "instantiate", "scene_has_tiles", "", "scene", "tile_11",
  446. "instantiate", "character_on", "", "Link", "tile_00",
  447. "instantiate", "item_on", "", "goal", "tile_11",
  448. "instantiate", "tile_left", "", "tile_01", "tile_00",
  449. "instantiate", "tile_left", "", "tile_11", "tile_10",
  450. "instantiate", "tile_right", "", "tile_00", "tile_01",
  451. "instantiate", "tile_right", "", "tile_10", "tile_11",
  452. "instantiate", "tile_top", "", "tile_10", "tile_00",
  453. "instantiate", "tile_top", "", "tile_11", "tile_01",
  454. "instantiate", "tile_bottom", "", "tile_00", "tile_10",
  455. "instantiate", "tile_bottom", "", "tile_01", "tile_11",
  456. "verify",
  457. ],
  458. init + new + loaded + \
  459. set_inheritance + prompt + \
  460. (instantiate_node + prompt) * 6 + \
  461. (instantiate_edge + prompt) * 9 + \
  462. (attr_add + prompt) * 20 + \
  463. ["Element to constrain (empty for global)?",
  464. "Give input to function constructors for LOCAL constraint!",
  465. "Added constraint to model!"] + \
  466. prompt + \
  467. ["OK"] + \
  468. prompt + prompt + new + loaded + \
  469. (instantiate_node + prompt) * 7 + \
  470. (instantiate_edge + prompt) * 14 + \
  471. ["OK"],
  472. mode))
  473. def test_po_pn_interface_transform_pn(self):
  474. constraint_code = \
  475. """
  476. include "primitives.alh"
  477. include "modelling.alh"
  478. include "object_operations.alh"
  479. Boolean function constraint(host_model : Element, name : String):
  480. \t// Make sure that all places have enough tokens
  481. \tElement links
  482. \tElement link
  483. \tElement place
  484. \tlinks = allIncomingAssociationInstances(host_model, name, "P2T")
  485. \twhile (read_nr_out(links) > 0):
  486. \t\tlink = set_pop(links)
  487. \t\tplace = readAssociationSource(host_model, link)
  488. \t\tif (integer_lt(read_attribute(host_model, place, "tokens"), read_attribute(host_model, link, "weight"))):
  489. \t\t\t// Not enough tokens for this weight
  490. \t\t\treturn False!
  491. \treturn True!
  492. """
  493. action_code = \
  494. """
  495. include "primitives.alh"
  496. include "modelling.alh"
  497. Void function action(host_model : Element, name : String, mapping : Element):
  498. \tunset_attribute(host_model, name, "executing")
  499. \tinstantiate_attribute(host_model, name, "executing", True)
  500. \treturn!
  501. """
  502. constructor_action = get_constructor(action_code)
  503. constructor_constraint = get_constructor(constraint_code)
  504. self.assertTrue(run_file(all_files,
  505. ["new", "SimpleClassDiagrams", "PetriNets_runtime",
  506. "set_inheritance", "Inheritance",
  507. "instantiate", "Class", "Natural",
  508. "instantiate", "Class", "Boolean",
  509. "instantiate", "Class", "Place",
  510. "attr_def", "Place", "tokens", "Natural",
  511. "attr_def", "Place", "executed", "Boolean",
  512. "instantiate", "Class", "Transition",
  513. "attr_def", "Transition", "executing", "Boolean",
  514. "instantiate", "Association", "P2T", "Place", "Transition",
  515. "attr_def", "P2T", "weight", "Natural",
  516. "instantiate", "Association", "T2P", "Transition", "Place",
  517. "attr_def", "T2P", "weight", "Natural",
  518. "exit",
  519. "new", "PetriNets_runtime", "pn",
  520. "instantiate", "Place", "p1",
  521. "attr_add", "p1", "tokens", 1,
  522. "attr_add", "p1", "executed", False,
  523. "instantiate", "Place", "p2",
  524. "attr_add", "p2", "tokens", 2,
  525. "attr_add", "p2", "executed", False,
  526. "instantiate", "Transition", "t1",
  527. "attr_add", "t1", "executing", False,
  528. "instantiate", "P2T", "p2t", "p1", "t1",
  529. "attr_add", "p2t", "weight", 2,
  530. "instantiate", "P2T", "p2t2", "p2", "t1",
  531. "attr_add", "p2t2", "weight", 1,
  532. "exit",
  533. "ramify", "PetriNets_runtime",
  534. "new", "PetriNets_runtime_PRE", "pn_LHS",
  535. "instantiate", "LHS", "lhs",
  536. "instantiate", "Pre_Transition", "t",
  537. "attr_add", "t", "label", "0",
  538. #"attr_add_code", "t", "constraint",
  539. #] + constructor_constraint + [
  540. "instantiate", "LHS_contains", "", "lhs", "t",
  541. "exit",
  542. "new", "PetriNets_runtime_POST", "pn_RHS",
  543. "instantiate", "RHS", "rhs",
  544. "instantiate", "Post_Transition", "t",
  545. "attr_add", "t", "label", "0",
  546. "attr_add_code", "t", "action",
  547. ] + constructor_action + [
  548. "instantiate", "RHS_contains", "", "rhs", "t",
  549. "exit",
  550. "transform", "pn", "pn_LHS", "pn_RHS",
  551. "load", "pn",
  552. "list",
  553. "verify",
  554. "read",
  555. "t1",
  556. "exit",
  557. ],
  558. None, "PO"))