pn_interface.alc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. include "primitives.alh"
  2. include "constructors.alh"
  3. include "object_operations.alh"
  4. include "library.alh"
  5. include "conformance_scd.alh"
  6. include "io.alh"
  7. include "metamodels.alh"
  8. include "modelling.alh"
  9. //helper function that returns the type of an attribute in string format
  10. Element function find_attribute_type_s(model : Element, elem : String, name : String):
  11. Element mm_elem
  12. Element direct_type
  13. direct_type = dict_read_node(model["type_mapping"], model["model"][elem])
  14. mm_elem = find_attribute_definer(model["metamodel"], direct_type, name)
  15. if (element_eq(mm_elem, read_root())):
  16. // Couldn't find element, so is not allowed!
  17. log("Undefined attribute!")
  18. return read_root()
  19. else:
  20. return getName(model["metamodel"], read_edge_dst( dict_read_edge(mm_elem, name)))
  21. //function to print information about a node (attributes, type and name)
  22. Element function printNode(tf_pn_model: Element, tf_pn_node: Element):
  23. //print header name
  24. String tf_pn_node_name
  25. tf_pn_node_name = getName(tf_pn_model, tf_pn_node)
  26. log(string_join("name: ",tf_pn_node_name) )
  27. log(string_join("type: ", getName(tf_pn_model["metamodel"], dict_read_node(tf_pn_model["type_mapping"], tf_pn_node)) ))
  28. //log(getName(tf_pn_model["metamodel"], dict_read_node(tf_pn_model["type_mapping"], tf_pn_node)))
  29. log("attributes:")
  30. //get the list of attributes
  31. Element tf_pn_attributelist
  32. tf_pn_attributelist = dict_keys(getAttributeList(tf_pn_model, tf_pn_node_name))
  33. String tf_pn_attributename
  34. String tf_pn_attributetype
  35. while (integer_lt(0, read_nr_out(tf_pn_attributelist))):
  36. //print attribute name and its value
  37. tf_pn_attributename = set_pop(tf_pn_attributelist)
  38. tf_pn_attributetype = find_attribute_type_s(tf_pn_model, tf_pn_node_name, tf_pn_attributename)
  39. if( tf_pn_attributetype == "String"):
  40. log(string_join(string_join(string_join(" ",tf_pn_attributename), " : "),read_attribute(tf_pn_model, tf_pn_node_name, tf_pn_attributename)))
  41. elif (tf_pn_attributetype == "Integer"):
  42. log(string_join(string_join(string_join(" ",tf_pn_attributename), " : "),cast_i2s(read_attribute(tf_pn_model, tf_pn_node_name, tf_pn_attributename))))
  43. else:
  44. log(string_join(tf_pn_attributename, " : "))
  45. log(read_attribute(tf_pn_model, tf_pn_node_name, tf_pn_attributename))
  46. return 0
  47. // given a pattern, this function will return all matches in a model
  48. Element function tf_matchAll(tf_ma_transformation: Element, tf_ma_pattern : Element, tf_ma_model: Element ):
  49. Element tf_ma_metamodelTransf
  50. tf_ma_metamodelTransf = dict_read(dict_read(tf_ma_transformation, "metamodel"), "model")
  51. Element tf_ma_pattern_nodes
  52. tf_ma_pattern_nodes = create_node()
  53. tf_ma_pattern_nodes = allOutgoingAssociationInstances(tf_ma_transformation, tf_ma_pattern, dict_read(tf_ma_metamodelTransf, "pre2ram"))
  54. //check if this works
  55. Element tf_ma_ramified_node
  56. while (integer_lt(0, read_nr_out(tf_ma_pattern_nodes))):
  57. tf_ma_ramified_node = read_edge_dst(set_pop(tf_ma_pattern_nodes))
  58. printNode(tf_ma_transformation, tf_ma_ramified_node)
  59. log(read_attribute(tf_ma_transformation, getName(tf_ma_transformation, tf_ma_ramified_node), "plabel"))
  60. return 0
  61. Element function tf_executeRule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element):
  62. Element tf_er_lhs
  63. // get the lhs of the rule
  64. tf_er_lhs = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "lhs"))
  65. // find the matches of the rule
  66. tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_lhs)), tf_er_model)
  67. return 0
  68. Element function tf_transform(tf_tf_transformation: Element, tf_tf_model: Element):
  69. //create a list of all rules
  70. Element tf_tf_rules
  71. tf_tf_rules = allInstances(tf_tf_transformation, dict_read(dict_read(dict_read(tf_tf_transformation, "metamodel"), "model"), "Rule"))
  72. //execute rules in random order
  73. Element tf_tf_rule
  74. while (integer_lt(0, read_nr_out(tf_tf_rules))):
  75. tf_tf_rule = set_pop(tf_tf_rules)
  76. //tf_printNode(tf_tf_transformation, tf_tf_rule)
  77. tf_executeRule(tf_tf_transformation, tf_tf_rule, tf_tf_model)
  78. return 0
  79. Element function petrinet_transformation(root: Element):
  80. // Create A transformation model for petrinets (useful for testing)
  81. //////////////////////////////////
  82. //initialise an empty transformation model for petrinet
  83. Element my_model
  84. my_model = instantiate_model(root["PetriNets_MTransformation"])
  85. define_inheritance(my_model, "l3")
  86. dict_add(root, "transf_petrinet_fire", my_model)
  87. ////////////////////////////
  88. // root node
  89. instantiate_node(my_model, "Transformation", "PetrinetFire")
  90. instantiate_attribute(my_model, "PetrinetFire", "name", "PetriNetFire")
  91. ////////////////////////////
  92. // rule: find transitions
  93. //rule: find_transitions
  94. instantiate_node(my_model, "Rule", "find_transitions")
  95. instantiate_attribute(my_model, "find_transitions", "name", "find_transitions")
  96. instantiate_attribute(my_model, "find_transitions", "precedence", 1)
  97. //connect to transformation
  98. instantiate_link(my_model, "transformation_to_rule", "", "PetrinetFire", "find_transitions")
  99. //precondition: lhs_precondition
  100. instantiate_node(my_model, "Precondition","lhs_precondition")
  101. //connect to rule
  102. instantiate_link(my_model, "lhs", "", "find_transitions", "lhs_precondition")
  103. //Transition_LHS: lhs_find_all
  104. instantiate_node(my_model, "Transition_LHS","lhs_find_all")
  105. instantiate_attribute(my_model, "lhs_find_all", "plabel", 1)
  106. //connect to rule
  107. instantiate_link(my_model, "pre2ram", "", "lhs_precondition", "lhs_find_all")
  108. //precondition: nac_precondition
  109. instantiate_node(my_model, "Precondition","nac_precondition")
  110. //connect to rule
  111. instantiate_link(my_model, "nac", "", "find_transitions", "nac_precondition")
  112. //Transition_LHS: nac_transition_place_before
  113. instantiate_node(my_model, "Transition_LHS","nac_transition_place_before")
  114. instantiate_attribute(my_model, "nac_transition_place_before", "plabel", 1)
  115. //connect to rule
  116. instantiate_link(my_model, "pre2ram", "", "nac_precondition", "nac_transition_place_before")
  117. //Place_LHS: nac_place_before
  118. instantiate_node(my_model, "Place_LHS","nac_place_before")
  119. instantiate_attribute(my_model, "nac_place_before", "plabel", 2)
  120. instantiate_attribute(my_model, "nac_place_before", "tokens", "lambda x: sum([1 for i in x.out if i.weight<x.tokens]) == len(x.transition)")
  121. //connect to rule
  122. instantiate_link(my_model, "pre2ram", "", "nac_precondition", "nac_place_before")
  123. //P2T_LHS: nac_ft_p2t
  124. instantiate_link(my_model, "P2T_LHS", "nac_p2tlhs_before", "nac_place_before", "nac_transition_place_before")
  125. instantiate_attribute(my_model, "nac_p2tlhs_before", "plabel", 3)
  126. instantiate_attribute(my_model, "nac_p2tlhs_before", "weight", "lambda x: True")
  127. //connect to rule
  128. instantiate_link(my_model, "pre2ram", "", "nac_precondition", "nac_p2tlhs_before")
  129. return my_model
  130. Element function pn_operations():
  131. Element ops
  132. ops = create_node()
  133. dict_add(ops, "fire", petrinet_fire)
  134. dict_add(ops, "enabled", petrinet_enabled)
  135. return ops
  136. Element function petrinet_enabled(model : Element):
  137. Element set_enabled
  138. set_enabled = petrinet_enabled_set(model)
  139. output("Enabled transitions:")
  140. while (0 < read_nr_out(set_enabled)):
  141. output(getName(model, set_pop(set_enabled)))
  142. return model
  143. Element function petrinet_enabled_set(model : Element):
  144. Element all_transitions
  145. all_transitions = allInstances(model, model["metamodel"]["model"]["Transition"])
  146. Element enabled_transitions
  147. enabled_transitions = create_node()
  148. Element under_study
  149. Element in_arcs
  150. Element arc_under_study
  151. Boolean enabled
  152. while (0 < read_nr_out(all_transitions)):
  153. under_study = set_pop(all_transitions)
  154. enabled = True
  155. // Find all incoming transitions
  156. in_arcs = allIncomingAssociationInstances(model, under_study, model["metamodel"]["model"]["P2T"])
  157. while (0 < read_nr_out(in_arcs)):
  158. arc_under_study = set_pop(in_arcs)
  159. Integer present_tokens
  160. Integer required_tokens
  161. required_tokens = read_attribute(model, getName(model, arc_under_study), "weight")
  162. present_tokens = read_attribute(model, getName(model, read_edge_src(arc_under_study)), "tokens")
  163. if (present_tokens < required_tokens):
  164. // Less tokens than required, so disable the transition completely
  165. enabled = False
  166. if (enabled):
  167. set_add(enabled_transitions, under_study)
  168. return enabled_transitions
  169. Element function petrinet_fire(model : Element):
  170. output("Transition to fire?")
  171. Element transition
  172. transition = input()
  173. if (dict_in(model["model"], transition)):
  174. transition = model["model"][transition]
  175. if (set_in(petrinet_enabled_set(model), transition)):
  176. Element workset
  177. Element working_place
  178. Element working_arc
  179. Integer new_value
  180. // Consume tokens
  181. workset = allIncomingAssociationInstances(model, transition, model["metamodel"]["model"]["P2T"])
  182. while (0 < read_nr_out(workset)):
  183. working_arc = set_pop(workset)
  184. working_place = read_edge_src(working_arc)
  185. new_value = integer_subtraction(read_attribute(model, getName(model, working_place), "tokens"), read_attribute(model, getName(model, working_arc), "weight"))
  186. unset_attribute(model, getName(model, working_place), "tokens")
  187. instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
  188. output(((" " + getName(model, working_place)) + ": ") + cast_i2s(read_attribute(model, getName(model, working_place), "tokens")))
  189. // Add tokens
  190. workset = allOutgoingAssociationInstances(model, transition, model["metamodel"]["model"]["T2P"])
  191. while (0 < read_nr_out(workset)):
  192. working_arc = set_pop(workset)
  193. working_place = read_edge_dst(working_arc)
  194. new_value = integer_addition(read_attribute(model, getName(model, working_place), "tokens"), read_attribute(model, getName(model, working_arc), "weight"))
  195. unset_attribute(model, getName(model, working_place), "tokens")
  196. instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
  197. output(((" " + getName(model, working_place)) + ": ") + cast_i2s(read_attribute(model, getName(model, working_place), "tokens")))
  198. output("Transition fired!")
  199. else:
  200. output("Cannot fire if not enabled; aborting")
  201. else:
  202. output("Unknown transition; aborting")
  203. return model
  204. Element function petrinet_loaded(model : Element):
  205. String cmd
  206. Element attr_list_pn
  207. Element attr_keys_pn
  208. String attr_key_pn
  209. Element metamodel_element_pn
  210. String typename
  211. Boolean bottom
  212. Element other_metamodel
  213. bottom = False
  214. other_metamodel = create_node()
  215. dict_add(other_metamodel, "model", model["model"])
  216. dict_add(other_metamodel, "type_mapping", create_node())
  217. dict_add(other_metamodel, "metamodel", import_node("models/LTM_bottom"))
  218. dict_add(other_metamodel, "inheritance", other_metamodel["metamodel"]["model"]["__Inheritance"])
  219. output("Model loaded, ready for commands!")
  220. output("Use 'help' command for a list of possible commands")
  221. while (True):
  222. output("Please give your command.")
  223. cmd = input()
  224. if (cmd == "help"):
  225. output("Generic model operations:")
  226. output(" instantiate -- Create a new model element")
  227. output(" delete -- Delete an existing element")
  228. output(" attr_add -- Add an attribute to an element")
  229. output(" attr_del -- Delete an attribute of an element")
  230. output(" rename -- Rename an existing element")
  231. output(" modify -- Modify the attributes of an element")
  232. output(" list -- Prints the list of elements in the model")
  233. output(" types -- Prints the list of elements that can be instantiated")
  234. output(" read -- Prints the current state of a model element")
  235. output(" verify -- Check whether the model conforms to the metamodel")
  236. output(" retype -- Change the type of an element")
  237. output(" switch -- Switch between conformance bottom and the linguistic metamodel")
  238. output(" exit -- Unload the model and go back to the loading prompt")
  239. if (bool_not(bottom)):
  240. output("Model-specific operations:")
  241. Element specific_ops
  242. specific_ops = dict_keys(pn_operations())
  243. String specific_op
  244. while (0 < dict_len(specific_ops)):
  245. specific_op = set_pop(specific_ops)
  246. output(" " + specific_op)
  247. elif (cmd == "exit"):
  248. return model
  249. elif (cmd == "instantiate"):
  250. String mm_type_name
  251. output("Type to instantiate?")
  252. mm_type_name = input()
  253. if (dict_in(model["metamodel"]["model"], mm_type_name)):
  254. String element_name
  255. output("Name of new element?")
  256. element_name = input()
  257. if (dict_in(model["model"], element_name)):
  258. output("Element already exists; aborting")
  259. else:
  260. if (is_edge(model["metamodel"]["model"][mm_type_name])):
  261. output("Source name?")
  262. String src_name
  263. src_name = input()
  264. if (dict_in(model["model"], src_name)):
  265. output("Destination name?")
  266. String dst_name
  267. dst_name = input()
  268. if (dict_in(model["model"], dst_name)):
  269. instantiate_link(model, mm_type_name, element_name, src_name, dst_name)
  270. if (dict_in(model["model"], element_name)):
  271. output("Instantiation successful!")
  272. else:
  273. output("Instantiation error!")
  274. else:
  275. output("Unknown destination; aborting")
  276. else:
  277. output("Unknown source; aborting")
  278. else:
  279. instantiate_node(model, mm_type_name, element_name)
  280. if (dict_in(model["model"], element_name)):
  281. output("Instantiation successful!")
  282. else:
  283. output("Instantiation error!")
  284. else:
  285. output("Unknown type specified; aborting")
  286. elif (cmd == "modify"):
  287. String model_name
  288. output("Element to modify?")
  289. model_name = input()
  290. if (dict_in(model["model"], model_name)):
  291. Element attrs
  292. attrs = getAttributeList(model, model_name)
  293. String attr_name
  294. output("Attribute to modify?")
  295. attr_name = input()
  296. if (set_in(dict_keys(attrs), attr_name)):
  297. output("New value?")
  298. unset_attribute(model, model_name, attr_name)
  299. instantiate_attribute(model, model_name, attr_name, input())
  300. output("Modified!")
  301. else:
  302. output("No such attribute!")
  303. else:
  304. output("No such model!")
  305. elif (cmd == "attr_add"):
  306. String model_name
  307. output("Which model do you want to assign an attribute to?")
  308. model_name = input()
  309. if (dict_in(model["model"], model_name)):
  310. Element attrs
  311. attrs = getAttributeList(model, model_name)
  312. String attr_name
  313. output("Which attribute do you wish to assign?")
  314. attr_name = input()
  315. if (set_in(dict_keys(attrs), attr_name)):
  316. output("Value of attribute?")
  317. instantiate_attribute(model, model_name, attr_name, input())
  318. output("Added attribute!")
  319. else:
  320. output("No such attribute!")
  321. else:
  322. output("No such model!")
  323. elif (cmd == "attr_del"):
  324. String model_name
  325. output("Which model do you want to remove an attribute of?")
  326. model_name = input()
  327. if (dict_in(model["model"], model_name)):
  328. Element attrs
  329. attrs = getAttributeList(model, model_name)
  330. output(print_dict(attrs))
  331. String attr_name
  332. output("Which attribute do you want to delete?")
  333. attr_name = input()
  334. if (set_in(dict_keys(attrs), attr_name)):
  335. unset_attribute(model, model_name, attr_name)
  336. else:
  337. output("No such attribute!")
  338. else:
  339. output("No such model!")
  340. elif (cmd == "delete"):
  341. output("What is the name of the element you want to delete?")
  342. cmd = input()
  343. if (dict_in(model["model"], cmd)):
  344. model_delete_element(model, cmd)
  345. output("Deleted!")
  346. else:
  347. output("No such element; aborting")
  348. elif (cmd == "rename"):
  349. output("Old name?")
  350. String old_name_e
  351. old_name_e = input()
  352. if (dict_in(model["model"], old_name_e)):
  353. output("New name?")
  354. String new_name_e
  355. new_name_e = input()
  356. if (dict_in(model["model"], new_name_e)):
  357. output("New name already used; aborting")
  358. else:
  359. dict_add(model["model"], new_name_e, model["model"][old_name_e])
  360. dict_delete(model["model"], old_name_e)
  361. output("Rename complete!")
  362. else:
  363. output("Unknown element; aborting")
  364. elif (cmd == "list"):
  365. Element keys_m
  366. keys_m = dict_keys(model["model"])
  367. output("List of all elements:")
  368. String v_m
  369. while (read_nr_out(keys_m) > 0):
  370. v_m = set_pop(keys_m)
  371. // Filter out anonymous objects
  372. typename = getName(model["metamodel"], dict_read_node(model["type_mapping"], model["model"][v_m]))
  373. if (bool_not(string_startswith(v_m, "__"))):
  374. output(((" " + v_m) + " : ") + typename)
  375. elif (cmd == "read"):
  376. output("Element to read?")
  377. cmd = input()
  378. if (dict_in(model["model"], cmd)):
  379. Element read_elem
  380. read_elem = model["model"][cmd]
  381. metamodel_element_pn = dict_read_node(model["type_mapping"], read_elem)
  382. output("Name: " + cmd)
  383. output("Type: " + getName(model["metamodel"], metamodel_element_pn))
  384. if (is_edge(read_elem)):
  385. output("Source: " + getName(model, read_edge_src(read_elem)))
  386. output("Destination: " + getName(model, read_edge_dst(read_elem)))
  387. if (cast_v2s(read_elem) != "None"):
  388. output("Value: " + cast_v2s(read_elem))
  389. output("Defines attributes:")
  390. attr_list_pn = getInstantiatableAttributes(model, read_elem)
  391. attr_keys_pn = dict_keys(attr_list_pn)
  392. while (0 < read_nr_out(attr_keys_pn)):
  393. attr_key_pn = set_pop(attr_keys_pn)
  394. output((((" " + attr_key_pn) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])))
  395. output("Attributes:")
  396. attr_list_pn = getAttributeList(model, cmd)
  397. attr_keys_pn = dict_keys(attr_list_pn)
  398. while (0 < read_nr_out(attr_keys_pn)):
  399. attr_key_pn = set_pop(attr_keys_pn)
  400. output(((((" " + cast_v2s(attr_key_pn)) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])) + " = ") + cast_v2s(read_attribute(model, getName(model, read_elem), attr_key_pn)))
  401. else:
  402. output("Unknown element; aborting")
  403. elif (cmd == "verify"):
  404. output(conformance_scd(model))
  405. elif (cmd == "types"):
  406. Element keys_t
  407. keys_t = dict_keys(model["metamodel"]["model"])
  408. output("List of types:")
  409. String v_t
  410. while (read_nr_out(keys_t) > 0):
  411. v_t = set_pop(keys_t)
  412. if (bool_not(string_startswith(v_t, "__"))):
  413. output(string_join((" " + v_t) + " : ", getName(model["metamodel"]["metamodel"], dict_read_node(model["metamodel"]["type_mapping"], model["metamodel"]["model"][v_t]))))
  414. elif (cmd == "retype"):
  415. output("Element to retype?")
  416. String elementname
  417. elementname = input()
  418. if (dict_in(model["model"], elementname)):
  419. output("New type")
  420. typename = input()
  421. if (dict_in(model["metamodel"]["model"], typename)):
  422. // OK, do the retyping
  423. // First try removing the previous type if it exists
  424. dict_delete(model["type_mapping"], model["model"][elementname])
  425. // Now add the new type
  426. dict_add(model["type_mapping"], model["model"][elementname], model["metamodel"]["model"][typename])
  427. output("Retyped!")
  428. else:
  429. output("Unknown type; aborting")
  430. else:
  431. output("Unknown element; aborting")
  432. elif (cmd == "switch"):
  433. bottom = bool_not(bottom)
  434. Element tmp_model
  435. tmp_model = model
  436. model = other_metamodel
  437. other_metamodel = tmp_model
  438. if (bottom):
  439. // The type mapping we are using is probably not complete for our model
  440. // so we completely recreate it from the model we have.
  441. output("Switching to conformance bottom mode!")
  442. generate_bottom_type_mapping(model)
  443. else:
  444. // We already switched the models and such, so we are already done!
  445. output("Switching to linguistic metamodel!")
  446. elif (bool_and(dict_in(pn_operations(), cmd), bool_not(bottom))):
  447. // A model-specific operation, so execute that one
  448. Element specific_op
  449. specific_op = dict_read(pn_operations(), cmd)
  450. specific_op(model)
  451. else:
  452. output("Unknown command; aborting")
  453. output("Use command 'help' to get a list of available commands")
  454. Element function initial_prompt():
  455. output("Welcome to the Model Management Interface, running live on the Modelverse!")
  456. output("Use 'help' command for a list of possible commands")
  457. String command
  458. Element root
  459. Element metamodel
  460. String name
  461. Element my_model
  462. String mm_name
  463. root = create_metamodels()
  464. while (True):
  465. output("Please give your command.")
  466. command = input()
  467. if (command == "help"):
  468. output("Currently no model is loaded, so your operations are limited to:")
  469. output(" new -- Create a new model and save it for future use")
  470. output(" load -- Load a previously made model")
  471. output(" rename -- Rename a previously made model")
  472. output(" delete -- Delete a previously made model")
  473. output(" list -- Show a list of all stored models")
  474. output(" help -- Show a list of possible commands")
  475. elif (command == "new"):
  476. output("Metamodel to instantiate?")
  477. mm_name = input()
  478. if (dict_in(root, mm_name)):
  479. output("Name of model?")
  480. name = input()
  481. if (dict_in(root, name)):
  482. output("Model exists; aborting")
  483. else:
  484. my_model = instantiate_model(root[mm_name])
  485. dict_add(root, name, my_model)
  486. petrinet_loaded(my_model)
  487. else:
  488. output("Unknown metamodel; aborting")
  489. elif (command == "load"):
  490. output("Model to load?")
  491. name = input()
  492. if (dict_in(root, name)):
  493. my_model = root[name]
  494. petrinet_loaded(my_model)
  495. else:
  496. output("Model not found; aborting")
  497. elif (command == "list"):
  498. Element keys
  499. String m_menu_list
  500. keys = dict_keys(root)
  501. output("Found models:")
  502. while (read_nr_out(keys) > 0):
  503. m_menu_list = set_pop(keys)
  504. output(((" " + m_menu_list) + " : ") + reverseNameLookup(root, root[m_menu_list]["metamodel"]))
  505. elif (command == "delete"):
  506. output("Model to delete?")
  507. name = input()
  508. if (dict_in(root, name)):
  509. dict_delete(root, name)
  510. output("Deleted!")
  511. else:
  512. output("Model not found; aborting")
  513. elif (command == "rename"):
  514. output("Old name?")
  515. String old_name
  516. old_name = input()
  517. if (dict_in(root, old_name)):
  518. output("New name?")
  519. String new_name
  520. new_name = input()
  521. if (dict_in(root, new_name)):
  522. output("Model exists; aborting")
  523. else:
  524. dict_add(root, new_name, root[old_name])
  525. dict_delete(root, old_name)
  526. output("Rename complete!")
  527. else:
  528. output("Model not found; aborting")
  529. else:
  530. output("Command not recognized, use 'help' for a list of possible commands")
  531. Void function main():
  532. //initial_prompt()
  533. log("==========================================================================")
  534. log("=== creating metamodels")
  535. Element root
  536. root = create_metamodels()
  537. log("=== load instantiation of transformation metamodel")
  538. Element transf
  539. transf = petrinet_transformation(root)
  540. log("=== check conformance of transformation")
  541. log(conformance_scd(transf))
  542. log("=== run transform")
  543. tf_transform(transf, create_node())
  544. log("=== done")
  545. log("==========================================================================")
  546. return