pn_interface.alc 25 KB

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