pn_interface.alc 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536
  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. //given a model and a node, it will return the name of it's type in the metamodel
  22. String function getTypeName(model:Element, node:Element):
  23. return getName(model["metamodel"], dict_read_node(model["type_mapping"], node))
  24. //given a model and a node it will return the name of it's type in the metametamodel
  25. String function getMetaTypeName(model:Element, node:Element):
  26. return getTypeName(model["metamodel"], dict_read_node(model["type_mapping"], node))
  27. Boolean function isAttributeRelated(model:Element, node:Element):
  28. if(getMetaTypeName(model, node) == "Type"):
  29. return True
  30. elif(getMetaTypeName(model, node) == "l5"):
  31. if(getMetaTypeName(model, read_edge_dst(node)) == "Type" ):
  32. return True
  33. return False
  34. //function to print information about a node (attributes, type and name)
  35. Element function printNode(tf_pn_model: Element, tf_pn_node: Element):
  36. //print header with name, metatype
  37. //print node_name
  38. String tf_pn_node_name
  39. tf_pn_node_name = getName(tf_pn_model, tf_pn_node)
  40. log(string_join("--name: ",tf_pn_node_name) )
  41. //print node type
  42. log(string_join("type: ", getTypeName(tf_pn_model, tf_pn_node) ))
  43. //print node metatype
  44. String metatype
  45. metatype = getMetaTypeName(tf_pn_model, tf_pn_node)
  46. log(string_join("metatype: ", metatype))
  47. if (isAttributeRelated(tf_pn_model, tf_pn_node)):
  48. log(">attribute related")
  49. //print attributes
  50. log("attributes:")
  51. //get the list of attributes
  52. Element tf_pn_attributelist
  53. tf_pn_attributelist = dict_keys(getAttributeList(tf_pn_model, tf_pn_node_name))
  54. String tf_pn_attributename
  55. String tf_pn_attributetype
  56. while (integer_lt(0, read_nr_out(tf_pn_attributelist))):
  57. //print attribute name and its value
  58. tf_pn_attributename = set_pop(tf_pn_attributelist)
  59. tf_pn_attributetype = find_attribute_type_s(tf_pn_model, tf_pn_node_name, tf_pn_attributename)
  60. if( tf_pn_attributetype == "String"):
  61. log(string_join(string_join(string_join(" ",tf_pn_attributename), " : "),read_attribute(tf_pn_model, tf_pn_node_name, tf_pn_attributename)))
  62. elif (tf_pn_attributetype == "Integer"):
  63. log(string_join(string_join(string_join(" ",tf_pn_attributename), " : "),cast_i2s(read_attribute(tf_pn_model, tf_pn_node_name, tf_pn_attributename))))
  64. else:
  65. log(string_join(tf_pn_attributename, " : "))
  66. log(read_attribute(tf_pn_model, tf_pn_node_name, tf_pn_attributename))
  67. return 0
  68. Element pivots
  69. Boolean function node_match(transf_model : Element, transf_elem : Element, host_model : Element, host_elem : Element):
  70. //type equality
  71. String type1
  72. type1 = getTypeName(transf_model, transf_elem)
  73. String type2
  74. type2 = string_join(getTypeName(host_model, host_elem), "_LHS")
  75. if (type1 != type2):
  76. return False
  77. //semantic check
  78. Element func
  79. func = transf_model["semantic_checks"][read_attribute(transf_model, getName(transf_model,transf_elem), "function")]
  80. //pivot check
  81. String pivotInName
  82. pivotInName = read_attribute(transf_model, getName(transf_model, transf_elem), "pivotIn")
  83. if(func(host_model, host_elem)):
  84. if( pivotInName == ""):
  85. return True
  86. else:
  87. if(set_in(pivots[pivotInName], getName(host_model,host_elem))):
  88. return True
  89. else:
  90. return False
  91. return False
  92. Integer function are_connected(model: Element, el1:Element, el2:Element):
  93. String el1_mmt
  94. String el2_mmt
  95. el1_mmt = getMetaTypeName(model, el1)
  96. el2_mmt = getMetaTypeName(model, el2)
  97. if ( el1_mmt == "Class" ):
  98. if(el2_mmt == "Class"):
  99. return 0 //not connected, no edge inbetween
  100. elif(el2_mmt == "l5"):
  101. if( element_eq(read_edge_src(el2) , el1)):
  102. return 1 //outgoing
  103. elif( element_eq(read_edge_dst(el2) , el1)):
  104. return 2 //incoming
  105. else:
  106. return 0 //the edge is not connected
  107. else:
  108. log("is_connected_to: unsupported type for second element")
  109. log(string_join("type = ", el2_mmt))
  110. elif (el1_mmt == "l5"):
  111. if( element_eq(read_edge_src(el1) , el2)):
  112. return 2 //incoming
  113. elif( element_eq(read_edge_dst(el1) , el2)):
  114. return 1 //outgoing
  115. else:
  116. return 0 //edge is not connected
  117. else:
  118. log("is_connected_to: unsupported type for first element")
  119. log(string_join("type = ", el1_mmt))
  120. return 0 // if the function doesn't support it, assume disconnected
  121. Element function new_SearchState(OldSearchState : Element, TransfModel : Element, NewTransfElem: Element, HostModel : Element, NewHostElem : Element):
  122. //some variables
  123. Element nss // new searchstate
  124. nss = create_node()
  125. Integer index // used for list looping
  126. Element elem // reusable loop variable
  127. //new MATCHES
  128. dict_add(nss, "matches", OldSearchState["matches"]) //hopefully works as a reference
  129. //new CURMATCH
  130. Element OldCurMatchKeys // for looping trough old curmatch (for copying)
  131. OldCurMatchKeys = dict_keys(OldSearchState["curmatch"])
  132. Element new_curmatch //the new curmatch
  133. new_curmatch = create_node()
  134. Element oldkey // loop variable
  135. while (integer_lt(0, list_len(OldCurMatchKeys))): //copying the old curmatch
  136. oldkey = set_pop(OldCurMatchKeys)
  137. dict_add(new_curmatch, oldkey, OldSearchState["curmatch"][oldkey]) //WARNING dict_read_node needed???
  138. Element newPair // the new pair to be added
  139. newPair = create_node()
  140. dict_add(newPair, "pn", NewTransfElem) //PatternNode
  141. dict_add(newPair, "hn", NewHostElem) // HostNode
  142. Integer plabel
  143. plabel = read_attribute(TransfModel, getName(TransfModel, NewTransfElem), "plabel")
  144. dict_add(new_curmatch, plabel, newPair) //add pair to new curmatch
  145. dict_add(nss, "curmatch", new_curmatch) //add curmatch to state
  146. //new N_PATTERN_OUT (copy everything but the new match elements)
  147. Element ol //old list = old pattern out
  148. Element nl //new list = new N pattern out
  149. ol = OldSearchState["N_pattern_out"]
  150. nl = create_node()
  151. index = 0
  152. while (index < list_len(ol)): //loop trough old list
  153. elem = list_read(ol, index)
  154. index = index + 1
  155. if(bool_not(element_eq(elem, NewTransfElem))):
  156. list_append(nl, elem)
  157. dict_add(nss, "N_pattern_out", nl)
  158. //new N_HOST_OUT (copy everything but the new match elements)
  159. ol = OldSearchState["N_host_out"]
  160. nl = create_node()
  161. index = 0
  162. while (index < list_len(ol)): //loop trough old list
  163. elem = list_read(ol, index)
  164. index = index + 1
  165. if(bool_not(element_eq(elem, NewHostElem))):
  166. list_append(nl, elem)
  167. dict_add(nss, "N_host_out", nl)
  168. //new N_PATTERN_IN (copy everything but the new match elements)
  169. ol = OldSearchState["N_pattern_in"]
  170. nl = create_node()
  171. index = 0
  172. while (index < list_len(ol)): //loop trough old list
  173. elem = list_read(ol, index)
  174. index = index + 1
  175. if(bool_not(element_eq(elem, NewTransfElem))):
  176. list_append(nl, elem)
  177. dict_add(nss, "N_pattern_in", nl)
  178. //new N_HOST_IN (copy everything but the new match elements
  179. ol = OldSearchState["N_host_in"]
  180. nl = create_node()
  181. index = 0
  182. while (index < list_len(ol)): //loop trough old list
  183. elem = list_read(ol, index)
  184. index = index + 1
  185. if(bool_not(element_eq(elem, NewHostElem))):
  186. list_append(nl, elem)
  187. dict_add(nss, "N_host_in", nl)
  188. //new V_PATTERN
  189. ol = OldSearchState["V_pattern"]
  190. nl = create_node()
  191. index = 0
  192. Integer connectedness
  193. while (index < list_len(ol)): //loop trough old list
  194. elem = list_read(ol, index)
  195. index = index + 1
  196. if(bool_not(element_eq(elem, NewTransfElem))):
  197. connectedness = are_connected(TransfModel, NewTransfElem, elem)
  198. if (connectedness == 0): // if not connected, keep in V
  199. list_append(nl, elem)
  200. elif (connectedness == 1): //if connected in outwards manner, don't keep in v and add to outlist
  201. list_append(nss["N_pattern_out"], elem)
  202. elif (connectedness == 2): //if connected in inwards manner, don't keep in v and add to inlist
  203. list_append(nss["N_pattern_in"], elem)
  204. else:
  205. log("new_SearchState: unsupported connectedness value")
  206. log(cast_i2s(connectedness))
  207. dict_add(nss, "V_pattern", nl)
  208. //new V_HOST
  209. ol = OldSearchState["V_host"]
  210. nl = create_node()
  211. index = 0
  212. while (index < list_len(ol)): //loop trough old list
  213. elem = list_read(ol, index)
  214. index = index + 1
  215. if(bool_not(element_eq(elem, NewHostElem))):
  216. connectedness = are_connected(HostModel, NewHostElem, elem)
  217. if (connectedness == 0): // if not connected, keep in V
  218. list_append(nl, elem)
  219. elif (connectedness == 1): //if connected in outwards manner, don't keep in v and add to outlist
  220. list_append(nss["N_host_out"], elem)
  221. elif (connectedness == 2): //if connected in inwards manner, don't keep in v and add to inlist
  222. list_append(nss["N_host_in"], elem)
  223. else:
  224. log("new_SearchState: unsupported connectedness value")
  225. log(cast_i2s(connectedness))
  226. dict_add(nss, "V_host", nl)
  227. // copy pattern_size
  228. dict_add(nss, "pattern_size", OldSearchState["pattern_size"])
  229. return nss
  230. Element function transf_vf2(SearchState: Element, transf_m : Element, host_m : Element):
  231. // get the current match from the search-state
  232. Element current_match
  233. current_match = dict_read(SearchState,"curmatch")
  234. //if match is complete: add to matches and return
  235. Integer pattern_size
  236. pattern_size = SearchState["pattern_size"]
  237. if pattern_size == list_len(current_match):
  238. list_append(SearchState["matches"], SearchState["curmatch"])
  239. //log("MATCHED")
  240. return SearchState
  241. //feasability checks
  242. if (list_len(SearchState["N_pattern_out"]) > list_len(SearchState["N_host_out"])):
  243. log("not feasible1")
  244. return SearchState
  245. if (list_len(SearchState["N_pattern_in"]) > list_len(SearchState["N_host_in"])):
  246. log("not feasible2")
  247. return SearchState
  248. if (list_len(SearchState["V_pattern"]) > list_len(SearchState["V_host"])):
  249. log("not feasible3")
  250. return SearchState
  251. //initialise some variables
  252. Integer index2 //an index used for looping trough host_list
  253. Element host_list // the set with host nodes to be considered
  254. Element pattern_node // node to be tested from the patterns side
  255. Element host_node //node to be tested from the hosts side
  256. Element nss //variable for storing next searchstate
  257. //search candidate
  258. if ( list_len(SearchState["N_pattern_out"]) > 0 ):
  259. //check for candidates in (N_pattern_out, N_host_out)
  260. host_list = SearchState["N_host_out"]
  261. pattern_node = list_read(SearchState["N_pattern_out"], 0)
  262. index2 = 0
  263. while (index2 < list_len(host_list)):
  264. host_node = list_read(host_list, index2)
  265. index2= index2 + 1
  266. if(node_match(transf_m, pattern_node, host_m, host_node)):
  267. nss = new_SearchState(SearchState, transf_m, pattern_node, host_m, host_node)
  268. nss = transf_vf2(nss, transf_m, host_m)
  269. dict_delete(SearchState, "matches")
  270. dict_add(SearchState, "matches", nss["matches"])
  271. elif ( list_len(SearchState["N_pattern_in"]) > 0 ):
  272. //check for candidates in (N_pattern_in, N_host_in)
  273. host_list = SearchState["N_host_in"]
  274. pattern_node = list_read(SearchState["N_pattern_in"], 0)
  275. index2 = 0
  276. while (index2 < list_len(host_list)):
  277. host_node = list_read(host_list, index2)
  278. index2= index2 + 1
  279. if(node_match(transf_m, pattern_node, host_m, host_node)):
  280. nss = new_SearchState(SearchState, transf_m, pattern_node, host_m, host_node)
  281. nss = transf_vf2(nss, transf_m, host_m)
  282. dict_delete(SearchState, "matches")
  283. dict_add(SearchState, "matches", nss["matches"])
  284. elif ( list_len(SearchState["V_pattern"]) > 0 ):
  285. //check for candidates in (V_pattern, V_host))
  286. host_list = SearchState["V_host"]
  287. pattern_node = list_read(SearchState["V_pattern"], 0)
  288. index2 = 0
  289. while (index2 < list_len(host_list)):
  290. host_node = list_read(host_list, index2)
  291. index2= index2 + 1
  292. if(node_match(transf_m, pattern_node, host_m, host_node)):
  293. nss = new_SearchState(SearchState, transf_m, pattern_node, host_m, host_node)
  294. nss = transf_vf2(nss, transf_m, host_m)
  295. dict_delete(SearchState, "matches")
  296. dict_add(SearchState, "matches", nss["matches"])
  297. else:
  298. log("no candidate found")
  299. return SearchState
  300. // given a pattern, this function will return all matches in a model
  301. Element function tf_matchAll(tf_ma_transformation: Element, tf_ma_pattern : Element, tf_ma_model: Element ):
  302. //find all nodes in the pattern
  303. Element tf_ma_metamodelTransf //transformation metamodel
  304. tf_ma_metamodelTransf = tf_ma_transformation["metamodel"]["model"]
  305. Element pre2ram_et // type of the pre2ram edge
  306. pre2ram_et = dict_read(tf_ma_metamodelTransf, "pre2ram")
  307. Element tf_ma_pattern_edges //all pre2ram edges
  308. tf_ma_pattern_edges = allOutgoingAssociationInstances(tf_ma_transformation, tf_ma_pattern, pre2ram_et)
  309. Element tf_ma_ramified_nodes //dict in the form plabel->node
  310. tf_ma_ramified_nodes = create_node()
  311. Element tf_ma_ramified_node
  312. while (integer_lt(0, list_len(tf_ma_pattern_edges))):
  313. tf_ma_ramified_node = read_edge_dst(set_pop(tf_ma_pattern_edges))
  314. list_append(tf_ma_ramified_nodes, tf_ma_ramified_node)
  315. //find all nodes in the graph that are not related to attributes: ie a userdefined type
  316. Element hostmodel_mm //metamodel of hostgraph
  317. hostmodel_mm = tf_ma_model["metamodel"]["model"]
  318. Element hostmodel_keys //keys of all elements in the model
  319. hostmodel_keys = dict_keys(tf_ma_model["model"])
  320. Element host_nodes //all nodes in the host graph
  321. host_nodes = create_node()
  322. Element host_model_key
  323. while (integer_lt(0, read_nr_out(hostmodel_keys))):
  324. host_model_key = set_pop(hostmodel_keys)
  325. if bool_not(isAttributeRelated(tf_ma_model, tf_ma_model["model"][host_model_key])):
  326. list_append(host_nodes, tf_ma_model["model"][host_model_key])
  327. // initialise the start-state
  328. //initialise an start state
  329. Element SearchState
  330. SearchState = create_node()
  331. dict_add(SearchState, "matches", create_node())
  332. dict_add(SearchState, "curmatch", create_node())
  333. dict_add(SearchState, "N_pattern_out", create_node())
  334. dict_add(SearchState, "N_host_out", create_node())
  335. dict_add(SearchState, "N_pattern_in", create_node())
  336. dict_add(SearchState, "N_host_in", create_node())
  337. dict_add(SearchState, "V_pattern", tf_ma_ramified_nodes)
  338. dict_add(SearchState, "V_host", host_nodes)
  339. dict_add(SearchState, "pattern_size", list_len(tf_ma_ramified_nodes))
  340. //call vf2 for the matching
  341. SearchState = transf_vf2(SearchState, tf_ma_transformation, tf_ma_model)
  342. return SearchState["matches"]
  343. Element function mergeLHSNAC(tf_er_lhs : Element, tf_er_nac: Element):
  344. Element final_matches
  345. final_matches = create_node()
  346. Element lhs_match
  347. Element nac_match
  348. Element lhs_match_keys
  349. Element lhs_match_key
  350. Boolean allow_match
  351. Integer nac_index
  352. while(list_len(tf_er_lhs) > 0):
  353. lhs_match = set_pop(tf_er_lhs)
  354. allow_match=True
  355. nac_index = 0
  356. while(bool_and(nac_index < read_nr_out(tf_er_nac), allow_match)):
  357. nac_match = list_read(tf_er_nac, nac_index)
  358. nac_index = nac_index + 1
  359. lhs_match_keys = dict_keys(lhs_match)
  360. while (bool_and(read_nr_out(lhs_match_keys)>0, allow_match)):
  361. lhs_match_key = set_pop(lhs_match_keys)
  362. if dict_in(nac_match, lhs_match_key):
  363. if (element_eq(nac_match[lhs_match_key]["hn"],lhs_match[lhs_match_key]["hn"])):
  364. allow_match = False
  365. if (allow_match):
  366. list_append(final_matches, lhs_match)
  367. return final_matches
  368. Element function extractPivots(final_matches : Element, tf_er_transformation : Element, tf_er_model : Element):
  369. Integer match_index
  370. match_index = 0
  371. Element pattern_match_node
  372. Element host_match_node
  373. Element lhs_match
  374. Element lhs_match_keys
  375. Element lhs_match_key
  376. String pivotOutName
  377. Element pivotSet
  378. pivotSet = create_node()
  379. while (match_index < read_nr_out(final_matches)):
  380. lhs_match = list_read(final_matches, match_index)
  381. match_index = match_index +1
  382. lhs_match_keys = dict_keys(lhs_match)
  383. while (read_nr_out(lhs_match_keys) > 0):
  384. lhs_match_key = set_pop(lhs_match_keys)
  385. pattern_match_node = lhs_match[lhs_match_key]["pn"]
  386. host_match_node = lhs_match[lhs_match_key]["hn"]
  387. pivotOutName = read_attribute(tf_er_transformation, getName(tf_er_transformation, pattern_match_node), "pivotOut")
  388. if(pivotOutName != ""):
  389. if ( bool_not(set_in(pivotSet, pivotOutName))):
  390. set_add(pivotSet, pivotOutName)
  391. if (dict_in(pivots, pivotOutName)):
  392. dict_delete(pivots, pivotOutName)
  393. dict_add(pivots, pivotOutName, create_node())
  394. set_add(pivots[pivotOutName], getName(tf_er_model,host_match_node))
  395. return 0
  396. Element function rhs_rewrite(final_matches : Element,plabel_to_rhsnode:Element, tf_er_transformation:Element, tf_er_model:Element ):
  397. //loop over all matches
  398. Integer match_index
  399. match_index = 0
  400. Element rhs_plabels
  401. Element rhs_plabel
  402. Element rhs_action
  403. String new_TypeName
  404. String new_MetaTypeName
  405. Element rhs_to_host //keep this mapping, so that we know wich nodes in the hostmodel new edges connect
  406. Element lhs_match_keys
  407. Element lhs_match_key
  408. Element host_match_node
  409. Element lhs_match
  410. Integer source_plabel
  411. Integer destination_plabel
  412. while (match_index < read_nr_out(final_matches)):
  413. lhs_match = list_read(final_matches, match_index)
  414. match_index = match_index +1
  415. //get set of plables
  416. rhs_plabels = dict_keys(plabel_to_rhsnode)
  417. //loop trough every node in the match
  418. lhs_match_keys = dict_keys(lhs_match)
  419. rhs_to_host = create_node()
  420. while (read_nr_out(lhs_match_keys) > 0):
  421. lhs_match_key = set_pop(lhs_match_keys)
  422. host_match_node = lhs_match[lhs_match_key]["hn"]
  423. if set_in(rhs_plabels, lhs_match_key): //if node matches plabel with rhs
  424. //run function
  425. rhs_action = read_attribute(tf_er_transformation,getName(tf_er_transformation, plabel_to_rhsnode[lhs_match_key]), "function")
  426. rhs_action = tf_er_transformation["actions"][rhs_action]
  427. rhs_action(tf_er_model, host_match_node)
  428. dict_add(rhs_to_host, lhs_match_key, host_match_node)
  429. //remove key from rhs_plabels
  430. set_remove(rhs_plabels, lhs_match_key)
  431. else: // if node doesn't match plabel with rhs
  432. model_delete_element(tf_er_model, getName(tf_er_model, host_match_node))
  433. //for each remaining rhs-key (it is not in the match, so should be added)
  434. while (read_nr_out(rhs_plabels) > 0):
  435. rhs_plabel = set_pop(rhs_plabels)
  436. //get type and metatype
  437. new_TypeName = string_substr(getTypeName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), 0,-4)
  438. new_MetaTypeName = getMetaTypeName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel])
  439. //if it is a node, than we can simply add it
  440. if (new_MetaTypeName == "Class"):
  441. host_match_node = instantiate_node(tf_er_model, new_TypeName, "")
  442. //run the function
  443. rhs_action = read_attribute(tf_er_transformation,getName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), "function")
  444. rhs_action = tf_er_transformation["actions"][rhs_action]
  445. rhs_action(tf_er_model, tf_er_model["model"][host_match_node])
  446. elif (new_MetaTypeName == "l5"):
  447. //if it is an edge, we can only add it of source and edge exist, else we have to store the edge and get it later
  448. source_plabel = read_attribute(tf_er_transformation, getName(tf_er_transformation, read_edge_src(plabel_to_rhsnode[rhs_plabel]) ) , "plabel")
  449. destination_plabel = read_attribute(tf_er_transformation, getName(tf_er_transformation, read_edge_dst(plabel_to_rhsnode[rhs_plabel]) ) , "plabel")
  450. if(bool_and(dict_in(rhs_to_host, source_plabel), dict_in(rhs_to_host, destination_plabel))):
  451. rhs_action = instantiate_link(tf_er_model, new_TypeName, "", getName(tf_er_transformation, read_edge_src(plabel_to_rhsnode[rhs_plabel])), getName(tf_er_transformation, read_edge_dst(plabel_to_rhsnode[rhs_plabel])))
  452. //run function
  453. rhs_action = read_attribute(tf_er_transformation,getName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), "function")
  454. rhs_action = tf_er_transformation["actions"][rhs_action]
  455. rhs_action(tf_er_model, tf_er_model["model"][host_match_node])
  456. else:
  457. //TODO this is wrong and might cause an infinite loop
  458. set_add(rhs_plabels, rhs_plabel)
  459. else:
  460. log("unsupported metatype in rhs")
  461. return 0
  462. Element function tf_executeFRule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element):
  463. //find LHS
  464. //TODO if no lhs (is this allowed to happen?) // or empty lhs
  465. Element tf_er_lhs
  466. tf_er_lhs = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "lhs"))
  467. Integer nr_of_lhs_nodes
  468. nr_of_lhs_nodes = read_nr_out(tf_er_lhs)
  469. tf_er_lhs = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_lhs)), tf_er_model)
  470. Integer nr_of_lhs_matches
  471. nr_of_lhs_matches = list_len(tf_er_lhs)
  472. //find NACs if at least one lhs is found (otherwise not needed)
  473. Integer nr_of_nac_matches
  474. nr_of_nac_matches = 0
  475. Element tf_er_nac
  476. tf_er_nac = create_node()
  477. if(nr_of_lhs_matches > 0):
  478. Element tf_er_nac_
  479. tf_er_nac_ = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "nac"))
  480. Element partial_nac_matches
  481. while (read_nr_out(tf_er_nac_) > 0):
  482. partial_nac_matches = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_nac_)), tf_er_model)
  483. while (read_nr_out(partial_nac_matches)>0):
  484. list_append(tf_er_nac, set_pop(partial_nac_matches))
  485. nr_of_nac_matches = list_len(tf_er_nac)
  486. if( nr_of_lhs_nodes == 0):
  487. if (nr_of_nac_matches == 0):
  488. return True
  489. else:
  490. return False
  491. //remove from lhs matches that share a node with a nac match
  492. //TODO if nac is not related to match (no plabels match)
  493. Element final_matches
  494. final_matches = mergeLHSNAC(tf_er_lhs, tf_er_nac)
  495. if( read_nr_out(final_matches) == 0 ):
  496. return False
  497. //extract pivots from the matches
  498. extractPivots(final_matches, tf_er_transformation, tf_er_model)
  499. //rhs part
  500. //create plabel_to_rhsnode
  501. Element RHS
  502. RHS = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, tf_er_transformation["metamodel"]["model"]["rhs"])
  503. if(read_nr_out(RHS) > 0):
  504. RHS = read_edge_dst(set_pop(RHS))
  505. Element metamodelTransf //transformation metamodel
  506. metamodelTransf = tf_er_transformation["metamodel"]["model"]
  507. Element post2ram // type of the post2ram edge
  508. post2ram = dict_read(metamodelTransf, "post2ram")
  509. post2ram = allOutgoingAssociationInstances(tf_er_transformation, RHS, post2ram)
  510. Element plabel_to_rhsnode //dict in the form plabel->node
  511. plabel_to_rhsnode = create_node()
  512. Element rhs_node
  513. Integer rhs_plabel
  514. while (integer_lt(0, list_len(post2ram))):
  515. rhs_node = read_edge_dst(set_pop(post2ram))
  516. rhs_plabel = read_attribute(tf_er_transformation, getName(tf_er_transformation, rhs_node), "plabel")
  517. dict_add(plabel_to_rhsnode,rhs_plabel, rhs_node)
  518. rhs_rewrite(final_matches ,plabel_to_rhsnode, tf_er_transformation, tf_er_model )
  519. return True
  520. Integer function modulo(a:Integer,b:Integer):
  521. return a - integer_division(a,b)*b
  522. Integer RandomNumberState
  523. Integer function getRandomNumber(min:Integer, max:Integer):
  524. //returns a random integer in min and max range, never max
  525. if(min==max):
  526. return min
  527. if( bool_not(is_physical_int(RandomNumberState))):
  528. RandomNumberState = 4 // xkcd.com/221/
  529. RandomNumberState = modulo((8121*RandomNumberState) + 28411, 134456)
  530. return modulo(RandomNumberState , (max-min))+min
  531. Element function list_select_random(list:Element):
  532. return list_read(list, getRandomNumber(0,read_nr_out(list)))
  533. Element function tf_executeARule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element):
  534. //find LHS
  535. Element tf_er_lhs
  536. tf_er_lhs = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "lhs"))
  537. Integer nr_of_lhs_nodes
  538. nr_of_lhs_nodes = read_nr_out(tf_er_lhs)
  539. tf_er_lhs = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_lhs)), tf_er_model)
  540. Integer nr_of_lhs_matches
  541. nr_of_lhs_matches = list_len(tf_er_lhs)
  542. //find NACs if at least one lhs is found (otherwise not needed)
  543. Integer nr_of_nac_matches
  544. nr_of_nac_matches = 0
  545. Element tf_er_nac
  546. tf_er_nac = create_node()
  547. if(nr_of_lhs_matches > 0):
  548. Element tf_er_nac_
  549. tf_er_nac_ = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "nac"))
  550. Element partial_nac_matches
  551. while (read_nr_out(tf_er_nac_) > 0):
  552. partial_nac_matches = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_nac_)), tf_er_model)
  553. while (read_nr_out(partial_nac_matches)>0):
  554. list_append(tf_er_nac, set_pop(partial_nac_matches))
  555. nr_of_nac_matches = list_len(tf_er_nac)
  556. if( nr_of_lhs_nodes == 0):
  557. if (nr_of_nac_matches == 0):
  558. return True
  559. else:
  560. return False
  561. //remove from lhs matches that share a node with a nac match
  562. //TODO if nac is not related to match (no plabels match)
  563. Element final_matches
  564. final_matches = mergeLHSNAC(tf_er_lhs, tf_er_nac)
  565. if( read_nr_out(final_matches) == 0 ):
  566. return False
  567. //select only one match
  568. Element selected
  569. selected = list_select_random(final_matches)
  570. final_matches = create_node()
  571. list_append(final_matches, selected)
  572. //extract pivots from the matches
  573. extractPivots(final_matches, tf_er_transformation, tf_er_model)
  574. //rhs part
  575. //create plabel_to_rhsnode
  576. Element RHS
  577. RHS = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, tf_er_transformation["metamodel"]["model"]["rhs"])
  578. if(read_nr_out(RHS) > 0):
  579. RHS = read_edge_dst(set_pop(RHS))
  580. Element metamodelTransf //transformation metamodel
  581. metamodelTransf = tf_er_transformation["metamodel"]["model"]
  582. Element post2ram // type of the post2ram edge
  583. post2ram = dict_read(metamodelTransf, "post2ram")
  584. post2ram = allOutgoingAssociationInstances(tf_er_transformation, RHS, post2ram)
  585. Element plabel_to_rhsnode //dict in the form plabel->node
  586. plabel_to_rhsnode = create_node()
  587. Element rhs_node
  588. Integer rhs_plabel
  589. while (integer_lt(0, list_len(post2ram))):
  590. rhs_node = read_edge_dst(set_pop(post2ram))
  591. rhs_plabel = read_attribute(tf_er_transformation, getName(tf_er_transformation, rhs_node), "plabel")
  592. dict_add(plabel_to_rhsnode,rhs_plabel, rhs_node)
  593. rhs_rewrite(final_matches ,plabel_to_rhsnode, tf_er_transformation, tf_er_model )
  594. return True
  595. Element function executeRuleBlock(transformation_model : Element,hostmodel:Element, ruleblock : Element):
  596. //execute the correct ruletype
  597. //TODO define decent succes_value
  598. String typename
  599. typename = getTypeName(transformation_model, ruleblock)
  600. Boolean succes
  601. succes = False
  602. Element Rule
  603. if (typename == "RuleBlockRoot"):
  604. // do nothing
  605. log("= startinging transformation")
  606. succes = True
  607. elif (typename == "ARule"):
  608. log("= running ARule")
  609. Rule = read_edge_dst(set_pop(allOutgoingAssociationInstances(transformation_model, ruleblock, transformation_model["metamodel"]["model"]["getrule"])))
  610. log(getName(transformation_model, Rule))
  611. succes = tf_executeARule(transformation_model, Rule, hostmodel)
  612. elif (typename == "FRule"):
  613. log("= running FRule")
  614. Rule = read_edge_dst(set_pop(allOutgoingAssociationInstances(transformation_model, ruleblock, transformation_model["metamodel"]["model"]["getrule"])))
  615. log(getName(transformation_model, Rule))
  616. succes = tf_executeFRule(transformation_model, Rule, hostmodel)
  617. else:
  618. log("RuleType is not supported yet")
  619. //Return the next
  620. Element next
  621. if succes:
  622. next = allOutgoingAssociationInstances(transformation_model, ruleblock, transformation_model["metamodel"]["model"]["next_onSucces"])
  623. else:
  624. next = allOutgoingAssociationInstances(transformation_model, ruleblock, transformation_model["metamodel"]["model"]["next_onFailure"])
  625. if (read_nr_out(next) == 0):
  626. next = transformation_model
  627. else:
  628. next = read_edge_dst(set_pop(next))
  629. return next
  630. Element function tf_transform(tf_tf_transformation: Element, tf_tf_model: Element):
  631. //create a list of all rules
  632. Element ruleblock
  633. ruleblock = allInstances(tf_tf_transformation, tf_tf_transformation["metamodel"]["model"]["RuleBlockRoot"])
  634. if(read_nr_out(ruleblock) > 0):
  635. ruleblock = set_pop(ruleblock)
  636. pivots = create_node()
  637. Boolean continue
  638. continue = True
  639. while (continue):
  640. ruleblock = executeRuleBlock(tf_tf_transformation,tf_tf_model, ruleblock)
  641. if(element_eq(ruleblock,tf_tf_transformation)):
  642. log("finished")
  643. continue = False
  644. else:
  645. log("root ruleblock not found")
  646. return 0
  647. Element function test_simple_petrinet1(root:Element):
  648. //create a petrinet for testing purposes
  649. // P1 -> T1 -> P2 -> T2
  650. // m:1 w:1 w:2 m:0 w:1
  651. // l1 l2 l3
  652. //////////////////////////////////
  653. //initialise an empty petrinet
  654. Element my_model
  655. my_model = instantiate_model(root["PetriNets"])
  656. dict_add(root, "pnt_test1", my_model)
  657. // init t1
  658. instantiate_node(my_model, "Transition", "t1")
  659. // init p1
  660. instantiate_node(my_model, "Place", "p1")
  661. instantiate_attribute(my_model, "p1","tokens",1)
  662. // init link1
  663. instantiate_link(my_model, "P2T", "p1_to_t1", "p1", "t1")
  664. instantiate_attribute(my_model, "p1_to_t1", "weight", 1)
  665. //init p2
  666. instantiate_node(my_model, "Place", "p2")
  667. instantiate_attribute(my_model, "p2","tokens",0)
  668. //init link2
  669. instantiate_link(my_model, "T2P", "t1_to_p2", "t1", "p2")
  670. instantiate_attribute(my_model, "t1_to_p2", "weight", 2)
  671. //init t2
  672. instantiate_node(my_model, "Transition", "t2")
  673. //init link3
  674. instantiate_link(my_model, "P2T", "p2_to_t2", "p2", "t2")
  675. instantiate_attribute(my_model, "p2_to_t2", "weight", 1)
  676. return my_model
  677. Element function petrinet_transformation(root: Element):
  678. // Create A transformation model for petrinets (useful for testing)
  679. //////////////////////////////////
  680. //initialise an empty transformation model for petrinet
  681. Element my_model
  682. my_model = instantiate_model(root["PetriNets_MTransformation"])
  683. define_inheritance(my_model, "l3")
  684. dict_add(root, "transf_petrinet_fire", my_model)
  685. ////////////////////////////
  686. // root node
  687. instantiate_node(my_model, "Transformation", "PetrinetFire")
  688. instantiate_attribute(my_model, "PetrinetFire", "name", "PetriNetFire")
  689. ////////////////////////////
  690. // rule: find transitions
  691. //rule: find_transitions
  692. instantiate_node(my_model, "Rule", "find_transitions")
  693. instantiate_attribute(my_model, "find_transitions", "name", "find_transitions")
  694. instantiate_attribute(my_model, "find_transitions", "precedence", 1)
  695. //connect to transformation
  696. instantiate_link(my_model, "transformation_to_rule", "", "PetrinetFire", "find_transitions")
  697. //precondition: lhs_precondition
  698. instantiate_node(my_model, "Precondition","lhs_precondition")
  699. //connect to rule
  700. instantiate_link(my_model, "lhs", "", "find_transitions", "lhs_precondition")
  701. //Transition_LHS: lhs_find_all
  702. instantiate_node(my_model, "Transition_LHS","lhs_find_all")
  703. instantiate_attribute(my_model, "lhs_find_all", "plabel", 1)
  704. instantiate_attribute(my_model, "lhs_find_all", "function", "always_true")
  705. instantiate_attribute(my_model, "lhs_find_all", "pivotOut", "enabled")
  706. instantiate_attribute(my_model, "lhs_find_all", "pivotIn", "")
  707. //connect to rule
  708. instantiate_link(my_model, "pre2ram", "", "lhs_precondition", "lhs_find_all")
  709. //precondition: nac_precondition
  710. instantiate_node(my_model, "Precondition","nac_precondition")
  711. //connect to rule
  712. instantiate_link(my_model, "nac", "", "find_transitions", "nac_precondition")
  713. //Transition_LHS: nac_transition_place_before
  714. instantiate_node(my_model, "Transition_LHS","nac_transition_before")
  715. instantiate_attribute(my_model, "nac_transition_before", "plabel", 1)
  716. instantiate_attribute(my_model, "nac_transition_before", "function", "always_true")
  717. instantiate_attribute(my_model, "nac_transition_before", "pivotOut", "")
  718. instantiate_attribute(my_model, "nac_transition_before", "pivotIn", "")
  719. //connect to rule
  720. instantiate_link(my_model, "pre2ram", "", "nac_precondition", "nac_transition_before")
  721. //Place_LHS: nac_place_before
  722. instantiate_node(my_model, "Place_LHS","nac_place_before")
  723. instantiate_attribute(my_model, "nac_place_before", "plabel", 2)
  724. instantiate_attribute(my_model, "nac_place_before", "function", "always_true")
  725. instantiate_attribute(my_model, "nac_place_before", "pivotOut", "")
  726. instantiate_attribute(my_model, "nac_place_before", "pivotIn", "")
  727. //connect to rule
  728. instantiate_link(my_model, "pre2ram", "", "nac_precondition", "nac_place_before")
  729. //P2T_LHS: nac_ft_p2t
  730. instantiate_link(my_model, "P2T_LHS", "nac_p2tlhs_before", "nac_place_before", "nac_transition_before")
  731. instantiate_attribute(my_model, "nac_p2tlhs_before", "plabel", 3)
  732. instantiate_attribute(my_model, "nac_p2tlhs_before", "function", "is_not_consumable")
  733. instantiate_attribute(my_model, "nac_p2tlhs_before", "pivotOut", "")
  734. instantiate_attribute(my_model, "nac_p2tlhs_before", "pivotIn", "")
  735. //connect to rule
  736. instantiate_link(my_model, "pre2ram", "", "nac_precondition", "nac_p2tlhs_before")
  737. ////////////////////////////
  738. // rule: consume tokens
  739. //rule: consume_tokens
  740. instantiate_node(my_model, "Rule", "consume_tokens")
  741. instantiate_attribute(my_model, "consume_tokens", "name", "consume_tokens")
  742. instantiate_attribute(my_model, "consume_tokens", "precedence", 2)
  743. //connect to transformation
  744. instantiate_link(my_model, "transformation_to_rule", "", "PetrinetFire", "consume_tokens")
  745. //precondition: lhs_precondition
  746. instantiate_node(my_model, "Precondition","ct_lhs_precondition")
  747. //connect to rule
  748. instantiate_link(my_model, "lhs", "", "consume_tokens", "ct_lhs_precondition")
  749. //Transition_LHS: ct_lhs_transition
  750. instantiate_node(my_model, "Transition_LHS","ct_lhs_transition")
  751. instantiate_attribute(my_model, "ct_lhs_transition", "plabel", 1)
  752. instantiate_attribute(my_model, "ct_lhs_transition", "function", "always_true")
  753. instantiate_attribute(my_model, "ct_lhs_transition", "pivotOut", "")
  754. instantiate_attribute(my_model, "ct_lhs_transition", "pivotIn", "enabled")
  755. //connect to rule
  756. instantiate_link(my_model, "pre2ram", "", "ct_lhs_precondition", "ct_lhs_transition")
  757. //Place_LHS: ct_lhs_place
  758. instantiate_node(my_model, "Place_LHS","ct_lhs_place")
  759. instantiate_attribute(my_model, "ct_lhs_place", "plabel", 2)
  760. instantiate_attribute(my_model, "ct_lhs_place", "function", "always_true")
  761. instantiate_attribute(my_model, "ct_lhs_place", "pivotOut", "")
  762. instantiate_attribute(my_model, "ct_lhs_place", "pivotIn", "")
  763. //connect to rule
  764. instantiate_link(my_model, "pre2ram", "", "ct_lhs_precondition", "ct_lhs_place")
  765. //P2T_LHS: ct_lhs_link
  766. instantiate_link(my_model, "P2T_LHS", "ct_lhs_link", "ct_lhs_place", "ct_lhs_transition")
  767. instantiate_attribute(my_model, "ct_lhs_link", "plabel", 3)
  768. instantiate_attribute(my_model, "ct_lhs_link", "function", "always_true")
  769. instantiate_attribute(my_model, "ct_lhs_link", "pivotOut", "")
  770. instantiate_attribute(my_model, "ct_lhs_link", "pivotIn", "")
  771. //connect to rule
  772. instantiate_link(my_model, "pre2ram", "", "ct_lhs_precondition", "ct_lhs_link")
  773. //precondition: rhs_postcondition
  774. instantiate_node(my_model, "Postcondition","ct_rhs_postcondition")
  775. //connect to rule
  776. instantiate_link(my_model, "rhs", "", "consume_tokens", "ct_rhs_postcondition")
  777. //Transition_RHS: ct_rhs_transition
  778. instantiate_node(my_model, "Transition_RHS","ct_rhs_transition")
  779. instantiate_attribute(my_model, "ct_rhs_transition", "plabel", 1)
  780. instantiate_attribute(my_model, "ct_rhs_transition", "function", "do_nothing")
  781. instantiate_attribute(my_model, "ct_rhs_transition", "pivotOut", "")
  782. instantiate_attribute(my_model, "ct_rhs_transition", "pivotIn", "")
  783. //connect to rule
  784. instantiate_link(my_model, "post2ram", "", "ct_rhs_postcondition", "ct_rhs_transition")
  785. //Place_RHS: ct_rhs_place
  786. instantiate_node(my_model, "Place_RHS","ct_rhs_place")
  787. instantiate_attribute(my_model, "ct_rhs_place", "plabel", 2)
  788. instantiate_attribute(my_model, "ct_rhs_place", "function", "do_nothing")
  789. instantiate_attribute(my_model, "ct_rhs_place", "pivotOut", "")
  790. instantiate_attribute(my_model, "ct_rhs_place", "pivotIn", "")
  791. //connect to rule
  792. instantiate_link(my_model, "post2ram", "", "ct_rhs_postcondition", "ct_rhs_place")
  793. //P2T_RHS: ct_rhs_link
  794. instantiate_link(my_model, "P2T_RHS", "ct_rhs_link", "ct_rhs_place", "ct_rhs_transition")
  795. instantiate_attribute(my_model, "ct_rhs_link", "plabel", 3)
  796. instantiate_attribute(my_model, "ct_rhs_link", "function", "remove_tokens")
  797. instantiate_attribute(my_model, "ct_rhs_link", "pivotOut", "")
  798. instantiate_attribute(my_model, "ct_rhs_link", "pivotIn", "")
  799. //connect to rule
  800. instantiate_link(my_model, "post2ram", "", "ct_rhs_postcondition", "ct_rhs_link")
  801. ////////////////////////////
  802. // rule: produce tokens
  803. //rule: produce_tokens
  804. instantiate_node(my_model, "Rule", "produce_tokens")
  805. instantiate_attribute(my_model, "produce_tokens", "name", "produce_tokens")
  806. instantiate_attribute(my_model, "produce_tokens", "precedence", 3)
  807. //connect to transformation
  808. instantiate_link(my_model, "transformation_to_rule", "", "PetrinetFire", "produce_tokens")
  809. //precondition: lhs_precondition
  810. instantiate_node(my_model, "Precondition","pt_lhs_precondition")
  811. //connect to rule
  812. instantiate_link(my_model, "lhs", "", "produce_tokens", "pt_lhs_precondition")
  813. //Transition_LHS: pt_lhs_transition
  814. instantiate_node(my_model, "Transition_LHS","pt_lhs_transition")
  815. instantiate_attribute(my_model, "pt_lhs_transition", "plabel", 1)
  816. instantiate_attribute(my_model, "pt_lhs_transition", "function", "always_true")
  817. instantiate_attribute(my_model, "pt_lhs_transition", "pivotOut", "")
  818. instantiate_attribute(my_model, "pt_lhs_transition", "pivotIn", "enabled")
  819. //connect to rule
  820. instantiate_link(my_model, "pre2ram", "", "pt_lhs_precondition", "pt_lhs_transition")
  821. //Place_LHS: pt_lhs_place
  822. instantiate_node(my_model, "Place_LHS","pt_lhs_place")
  823. instantiate_attribute(my_model, "pt_lhs_place", "plabel", 2)
  824. instantiate_attribute(my_model, "pt_lhs_place", "function", "always_true")
  825. instantiate_attribute(my_model, "pt_lhs_place", "pivotOut", "")
  826. instantiate_attribute(my_model, "pt_lhs_place", "pivotIn", "")
  827. //connect to rule
  828. instantiate_link(my_model, "pre2ram", "", "pt_lhs_precondition", "pt_lhs_place")
  829. //P2T_LHS: pt_lhs_link
  830. instantiate_link(my_model, "T2P_LHS", "pt_lhs_link", "pt_lhs_transition", "pt_lhs_place")
  831. instantiate_attribute(my_model, "pt_lhs_link", "plabel", 3)
  832. instantiate_attribute(my_model, "pt_lhs_link", "function", "always_true")
  833. instantiate_attribute(my_model, "pt_lhs_link", "pivotOut", "")
  834. instantiate_attribute(my_model, "pt_lhs_link", "pivotIn", "")
  835. //connect to rule
  836. instantiate_link(my_model, "pre2ram", "", "pt_lhs_precondition", "pt_lhs_link")
  837. //precondition: rhs_postcondition
  838. instantiate_node(my_model, "Postcondition","pt_rhs_postcondition")
  839. //connect to rule
  840. instantiate_link(my_model, "rhs", "", "produce_tokens", "pt_rhs_postcondition")
  841. //Transition_RHS: pt_rhs_transition
  842. instantiate_node(my_model, "Transition_RHS","pt_rhs_transition")
  843. instantiate_attribute(my_model, "pt_rhs_transition", "plabel", 1)
  844. instantiate_attribute(my_model, "pt_rhs_transition", "function", "do_nothing")
  845. instantiate_attribute(my_model, "pt_rhs_transition", "pivotOut", "")
  846. instantiate_attribute(my_model, "pt_rhs_transition", "pivotIn", "")
  847. //connect to rule
  848. instantiate_link(my_model, "post2ram", "", "pt_rhs_postcondition", "pt_rhs_transition")
  849. //Place_RHS: pt_rhs_place
  850. instantiate_node(my_model, "Place_RHS","pt_rhs_place")
  851. instantiate_attribute(my_model, "pt_rhs_place", "plabel", 2)
  852. instantiate_attribute(my_model, "pt_rhs_place", "function", "do_nothing")
  853. instantiate_attribute(my_model, "pt_rhs_place", "pivotOut", "")
  854. instantiate_attribute(my_model, "pt_rhs_place", "pivotIn", "")
  855. //connect to rule
  856. instantiate_link(my_model, "post2ram", "", "pt_rhs_postcondition", "pt_rhs_place")
  857. //P2T_RHS: ct_rhs_link
  858. instantiate_link(my_model, "T2P_RHS", "pt_rhs_link", "pt_rhs_transition", "pt_rhs_place")
  859. instantiate_attribute(my_model, "pt_rhs_link", "plabel", 3)
  860. instantiate_attribute(my_model, "pt_rhs_link", "function", "add_tokens")
  861. instantiate_attribute(my_model, "pt_rhs_link", "pivotOut", "")
  862. instantiate_attribute(my_model, "pt_rhs_link", "pivotIn", "")
  863. //connect to rule
  864. instantiate_link(my_model, "post2ram", "", "pt_rhs_postcondition", "pt_rhs_link")
  865. ////////////////////////////
  866. // rule ordering part
  867. //start node
  868. instantiate_node(my_model, "RuleBlockRoot", "rule_root")
  869. //ARule: enabled
  870. instantiate_node(my_model, "ARule", "arule1")
  871. //connect to startnode
  872. instantiate_link(my_model, "next_onSucces", "", "rule_root", "arule1")
  873. //connect to rule
  874. instantiate_link(my_model, "getrule","", "arule1", "find_transitions")
  875. //FRule: consume
  876. instantiate_node(my_model, "FRule", "frule2")
  877. //connect to arule1
  878. instantiate_link(my_model, "next_onSucces", "", "arule1", "frule2")
  879. //connect to rule
  880. instantiate_link(my_model, "getrule","", "frule2", "consume_tokens")
  881. //Frule: produce
  882. instantiate_node(my_model, "FRule", "frule3")
  883. //connect to frule2
  884. instantiate_link(my_model, "next_onSucces", "", "frule2", "frule3")
  885. //connect to rule
  886. instantiate_link(my_model, "getrule","", "frule3", "produce_tokens")
  887. //create circularity link
  888. instantiate_link(my_model, "next_onSucces", "", "frule3", "arule1")
  889. //if you cannot consume, still try to produce (for source transitions)
  890. instantiate_link(my_model, "next_onFailure", "", "frule2", "frule3")
  891. //if you cannot produce, still check for other transitions (it might have consumed already)
  892. instantiate_link(my_model, "next_onFailure", "", "frule3", "arule1")
  893. ////////////////////////////
  894. // semantic checks
  895. Element semantic_checks
  896. semantic_checks = create_node()
  897. dict_add(semantic_checks, "always_true", always_true)
  898. dict_add(semantic_checks, "is_not_consumable", is_not_consumable)
  899. dict_add(my_model, "semantic_checks", semantic_checks)
  900. Element actions
  901. actions = create_node()
  902. dict_add(actions, "do_nothing", do_nothing)
  903. dict_add(actions, "add_tokens", add_tokens)
  904. dict_add(actions, "remove_tokens", remove_tokens)
  905. dict_add(my_model, "actions", actions)
  906. return my_model
  907. Boolean function is_not_consumable(model : Element, matched_node : Element):
  908. //get place before
  909. Element place_before
  910. place_before = read_edge_src(matched_node)
  911. //get tokens from place
  912. Integer tokens
  913. tokens = read_attribute(model, getName(model, place_before), "tokens")
  914. //get weight from matched_node
  915. Integer weight
  916. weight = read_attribute(model, getName(model, matched_node), "weight")
  917. return weight > tokens
  918. Boolean function always_true(model : Element, self : Element):
  919. return True
  920. Element function do_nothing(model: Element, self : Element):
  921. return 0
  922. Element function remove_tokens(model:Element, self: Element):
  923. //get place before
  924. Element place_before
  925. place_before = read_edge_src(self)
  926. //get tokens from place
  927. Integer tokens
  928. tokens = read_attribute(model, getName(model, place_before), "tokens")
  929. //get weight from matched_node
  930. Integer weight
  931. weight = read_attribute(model, getName(model, self), "weight")
  932. //rewrite tokens
  933. unset_attribute(model, getName(model, place_before), "tokens")
  934. instantiate_attribute(model, getName(model, place_before), "tokens", tokens-weight)
  935. return 0
  936. Element function add_tokens(model:Element, self: Element):
  937. //get place before
  938. Element place_after
  939. place_after = read_edge_dst(self)
  940. //get tokens from place
  941. Integer tokens
  942. tokens = read_attribute(model, getName(model, place_after), "tokens")
  943. //get weight from matched_node
  944. Integer weight
  945. weight = read_attribute(model, getName(model, self), "weight")
  946. //rewrite tokens
  947. unset_attribute(model, getName(model, place_after), "tokens")
  948. instantiate_attribute(model, getName(model, place_after), "tokens", tokens+weight)
  949. return 0
  950. Element function pn_operations():
  951. Element ops
  952. ops = create_node()
  953. dict_add(ops, "fire", petrinet_fire)
  954. dict_add(ops, "enabled", petrinet_enabled)
  955. return ops
  956. Element function petrinet_enabled(model : Element):
  957. Element set_enabled
  958. set_enabled = petrinet_enabled_set(model)
  959. output("Enabled transitions:")
  960. while (0 < read_nr_out(set_enabled)):
  961. output(getName(model, set_pop(set_enabled)))
  962. return model
  963. Element function petrinet_enabled_set(model : Element):
  964. Element all_transitions
  965. all_transitions = allInstances(model, model["metamodel"]["model"]["Transition"])
  966. Element enabled_transitions
  967. enabled_transitions = create_node()
  968. Element under_study
  969. Element in_arcs
  970. Element arc_under_study
  971. Boolean enabled
  972. while (0 < read_nr_out(all_transitions)):
  973. under_study = set_pop(all_transitions)
  974. enabled = True
  975. // Find all incoming transitions
  976. in_arcs = allIncomingAssociationInstances(model, under_study, model["metamodel"]["model"]["P2T"])
  977. while (0 < read_nr_out(in_arcs)):
  978. arc_under_study = set_pop(in_arcs)
  979. Integer present_tokens
  980. Integer required_tokens
  981. required_tokens = read_attribute(model, getName(model, arc_under_study), "weight")
  982. present_tokens = read_attribute(model, getName(model, read_edge_src(arc_under_study)), "tokens")
  983. if (present_tokens < required_tokens):
  984. // Less tokens than required, so disable the transition completely
  985. enabled = False
  986. if (enabled):
  987. set_add(enabled_transitions, under_study)
  988. return enabled_transitions
  989. Element function petrinet_fire(model : Element):
  990. output("Transition to fire?")
  991. Element transition
  992. transition = input()
  993. if (dict_in(model["model"], transition)):
  994. transition = model["model"][transition]
  995. if (set_in(petrinet_enabled_set(model), transition)):
  996. Element workset
  997. Element working_place
  998. Element working_arc
  999. Integer new_value
  1000. // Consume tokens
  1001. workset = allIncomingAssociationInstances(model, transition, model["metamodel"]["model"]["P2T"])
  1002. while (0 < read_nr_out(workset)):
  1003. working_arc = set_pop(workset)
  1004. working_place = read_edge_src(working_arc)
  1005. new_value = integer_subtraction(read_attribute(model, getName(model, working_place), "tokens"), read_attribute(model, getName(model, working_arc), "weight"))
  1006. unset_attribute(model, getName(model, working_place), "tokens")
  1007. instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
  1008. output(((" " + getName(model, working_place)) + ": ") + cast_i2s(read_attribute(model, getName(model, working_place), "tokens")))
  1009. // Add tokens
  1010. workset = allOutgoingAssociationInstances(model, transition, model["metamodel"]["model"]["T2P"])
  1011. while (0 < read_nr_out(workset)):
  1012. working_arc = set_pop(workset)
  1013. working_place = read_edge_dst(working_arc)
  1014. new_value = integer_addition(read_attribute(model, getName(model, working_place), "tokens"), read_attribute(model, getName(model, working_arc), "weight"))
  1015. unset_attribute(model, getName(model, working_place), "tokens")
  1016. instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
  1017. output(((" " + getName(model, working_place)) + ": ") + cast_i2s(read_attribute(model, getName(model, working_place), "tokens")))
  1018. output("Transition fired!")
  1019. else:
  1020. output("Cannot fire if not enabled; aborting")
  1021. else:
  1022. output("Unknown transition; aborting")
  1023. return model
  1024. Element function petrinet_loaded(model : Element):
  1025. String cmd
  1026. Element attr_list_pn
  1027. Element attr_keys_pn
  1028. String attr_key_pn
  1029. Element metamodel_element_pn
  1030. String typename
  1031. Boolean bottom
  1032. Element other_metamodel
  1033. bottom = False
  1034. other_metamodel = create_node()
  1035. dict_add(other_metamodel, "model", model["model"])
  1036. dict_add(other_metamodel, "type_mapping", create_node())
  1037. dict_add(other_metamodel, "metamodel", import_node("models/LTM_bottom"))
  1038. dict_add(other_metamodel, "inheritance", other_metamodel["metamodel"]["model"]["__Inheritance"])
  1039. output("Model loaded, ready for commands!")
  1040. output("Use 'help' command for a list of possible commands")
  1041. while (True):
  1042. output("Please give your command.")
  1043. cmd = input()
  1044. if (cmd == "help"):
  1045. output("Generic model operations:")
  1046. output(" instantiate -- Create a new model element")
  1047. output(" delete -- Delete an existing element")
  1048. output(" attr_add -- Add an attribute to an element")
  1049. output(" attr_del -- Delete an attribute of an element")
  1050. output(" rename -- Rename an existing element")
  1051. output(" modify -- Modify the attributes of an element")
  1052. output(" list -- Prints the list of elements in the model")
  1053. output(" types -- Prints the list of elements that can be instantiated")
  1054. output(" read -- Prints the current state of a model element")
  1055. output(" verify -- Check whether the model conforms to the metamodel")
  1056. output(" retype -- Change the type of an element")
  1057. output(" switch -- Switch between conformance bottom and the linguistic metamodel")
  1058. output(" exit -- Unload the model and go back to the loading prompt")
  1059. if (bool_not(bottom)):
  1060. output("Model-specific operations:")
  1061. Element specific_ops
  1062. specific_ops = dict_keys(pn_operations())
  1063. String specific_op
  1064. while (0 < dict_len(specific_ops)):
  1065. specific_op = set_pop(specific_ops)
  1066. output(" " + specific_op)
  1067. elif (cmd == "exit"):
  1068. return model
  1069. elif (cmd == "instantiate"):
  1070. String mm_type_name
  1071. output("Type to instantiate?")
  1072. mm_type_name = input()
  1073. if (dict_in(model["metamodel"]["model"], mm_type_name)):
  1074. String element_name
  1075. output("Name of new element?")
  1076. element_name = input()
  1077. if (dict_in(model["model"], element_name)):
  1078. output("Element already exists; aborting")
  1079. else:
  1080. if (is_edge(model["metamodel"]["model"][mm_type_name])):
  1081. output("Source name?")
  1082. String src_name
  1083. src_name = input()
  1084. if (dict_in(model["model"], src_name)):
  1085. output("Destination name?")
  1086. String dst_name
  1087. dst_name = input()
  1088. if (dict_in(model["model"], dst_name)):
  1089. instantiate_link(model, mm_type_name, element_name, src_name, dst_name)
  1090. if (dict_in(model["model"], element_name)):
  1091. output("Instantiation successful!")
  1092. else:
  1093. output("Instantiation error!")
  1094. else:
  1095. output("Unknown destination; aborting")
  1096. else:
  1097. output("Unknown source; aborting")
  1098. else:
  1099. instantiate_node(model, mm_type_name, element_name)
  1100. if (dict_in(model["model"], element_name)):
  1101. output("Instantiation successful!")
  1102. else:
  1103. output("Instantiation error!")
  1104. else:
  1105. output("Unknown type specified; aborting")
  1106. elif (cmd == "modify"):
  1107. String model_name
  1108. output("Element to modify?")
  1109. model_name = input()
  1110. if (dict_in(model["model"], model_name)):
  1111. Element attrs
  1112. attrs = getAttributeList(model, model_name)
  1113. String attr_name
  1114. output("Attribute to modify?")
  1115. attr_name = input()
  1116. if (set_in(dict_keys(attrs), attr_name)):
  1117. output("New value?")
  1118. unset_attribute(model, model_name, attr_name)
  1119. instantiate_attribute(model, model_name, attr_name, input())
  1120. output("Modified!")
  1121. else:
  1122. output("No such attribute!")
  1123. else:
  1124. output("No such model!")
  1125. elif (cmd == "attr_add"):
  1126. String model_name
  1127. output("Which model do you want to assign an attribute to?")
  1128. model_name = input()
  1129. if (dict_in(model["model"], model_name)):
  1130. Element attrs
  1131. attrs = getAttributeList(model, model_name)
  1132. String attr_name
  1133. output("Which attribute do you wish to assign?")
  1134. attr_name = input()
  1135. if (set_in(dict_keys(attrs), attr_name)):
  1136. output("Value of attribute?")
  1137. instantiate_attribute(model, model_name, attr_name, input())
  1138. output("Added attribute!")
  1139. else:
  1140. output("No such attribute!")
  1141. else:
  1142. output("No such model!")
  1143. elif (cmd == "attr_del"):
  1144. String model_name
  1145. output("Which model do you want to remove an attribute of?")
  1146. model_name = input()
  1147. if (dict_in(model["model"], model_name)):
  1148. Element attrs
  1149. attrs = getAttributeList(model, model_name)
  1150. output(print_dict(attrs))
  1151. String attr_name
  1152. output("Which attribute do you want to delete?")
  1153. attr_name = input()
  1154. if (set_in(dict_keys(attrs), attr_name)):
  1155. unset_attribute(model, model_name, attr_name)
  1156. else:
  1157. output("No such attribute!")
  1158. else:
  1159. output("No such model!")
  1160. elif (cmd == "delete"):
  1161. output("What is the name of the element you want to delete?")
  1162. cmd = input()
  1163. if (dict_in(model["model"], cmd)):
  1164. model_delete_element(model, cmd)
  1165. output("Deleted!")
  1166. else:
  1167. output("No such element; aborting")
  1168. elif (cmd == "rename"):
  1169. output("Old name?")
  1170. String old_name_e
  1171. old_name_e = input()
  1172. if (dict_in(model["model"], old_name_e)):
  1173. output("New name?")
  1174. String new_name_e
  1175. new_name_e = input()
  1176. if (dict_in(model["model"], new_name_e)):
  1177. output("New name already used; aborting")
  1178. else:
  1179. dict_add(model["model"], new_name_e, model["model"][old_name_e])
  1180. dict_delete(model["model"], old_name_e)
  1181. output("Rename complete!")
  1182. else:
  1183. output("Unknown element; aborting")
  1184. elif (cmd == "list"):
  1185. Element keys_m
  1186. keys_m = dict_keys(model["model"])
  1187. output("List of all elements:")
  1188. String v_m
  1189. while (read_nr_out(keys_m) > 0):
  1190. v_m = set_pop(keys_m)
  1191. // Filter out anonymous objects
  1192. typename = getName(model["metamodel"], dict_read_node(model["type_mapping"], model["model"][v_m]))
  1193. if (bool_not(string_startswith(v_m, "__"))):
  1194. output(((" " + v_m) + " : ") + typename)
  1195. elif (cmd == "read"):
  1196. output("Element to read?")
  1197. cmd = input()
  1198. if (dict_in(model["model"], cmd)):
  1199. Element read_elem
  1200. read_elem = model["model"][cmd]
  1201. metamodel_element_pn = dict_read_node(model["type_mapping"], read_elem)
  1202. output("Name: " + cmd)
  1203. output("Type: " + getName(model["metamodel"], metamodel_element_pn))
  1204. if (is_edge(read_elem)):
  1205. output("Source: " + getName(model, read_edge_src(read_elem)))
  1206. output("Destination: " + getName(model, read_edge_dst(read_elem)))
  1207. if (cast_v2s(read_elem) != "None"):
  1208. output("Value: " + cast_v2s(read_elem))
  1209. output("Defines attributes:")
  1210. attr_list_pn = getInstantiatableAttributes(model, read_elem)
  1211. attr_keys_pn = dict_keys(attr_list_pn)
  1212. while (0 < read_nr_out(attr_keys_pn)):
  1213. attr_key_pn = set_pop(attr_keys_pn)
  1214. output((((" " + attr_key_pn) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])))
  1215. output("Attributes:")
  1216. attr_list_pn = getAttributeList(model, cmd)
  1217. attr_keys_pn = dict_keys(attr_list_pn)
  1218. while (0 < read_nr_out(attr_keys_pn)):
  1219. attr_key_pn = set_pop(attr_keys_pn)
  1220. 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)))
  1221. else:
  1222. output("Unknown element; aborting")
  1223. elif (cmd == "verify"):
  1224. output(conformance_scd(model))
  1225. elif (cmd == "types"):
  1226. Element keys_t
  1227. keys_t = dict_keys(model["metamodel"]["model"])
  1228. output("List of types:")
  1229. String v_t
  1230. while (read_nr_out(keys_t) > 0):
  1231. v_t = set_pop(keys_t)
  1232. if (bool_not(string_startswith(v_t, "__"))):
  1233. output(string_join((" " + v_t) + " : ", getName(model["metamodel"]["metamodel"], dict_read_node(model["metamodel"]["type_mapping"], model["metamodel"]["model"][v_t]))))
  1234. elif (cmd == "retype"):
  1235. output("Element to retype?")
  1236. String elementname
  1237. elementname = input()
  1238. if (dict_in(model["model"], elementname)):
  1239. output("New type")
  1240. typename = input()
  1241. if (dict_in(model["metamodel"]["model"], typename)):
  1242. // OK, do the retyping
  1243. // First try removing the previous type if it exists
  1244. dict_delete(model["type_mapping"], model["model"][elementname])
  1245. // Now add the new type
  1246. dict_add(model["type_mapping"], model["model"][elementname], model["metamodel"]["model"][typename])
  1247. output("Retyped!")
  1248. else:
  1249. output("Unknown type; aborting")
  1250. else:
  1251. output("Unknown element; aborting")
  1252. elif (cmd == "switch"):
  1253. bottom = bool_not(bottom)
  1254. Element tmp_model
  1255. tmp_model = model
  1256. model = other_metamodel
  1257. other_metamodel = tmp_model
  1258. if (bottom):
  1259. // The type mapping we are using is probably not complete for our model
  1260. // so we completely recreate it from the model we have.
  1261. output("Switching to conformance bottom mode!")
  1262. generate_bottom_type_mapping(model)
  1263. else:
  1264. // We already switched the models and such, so we are already done!
  1265. output("Switching to linguistic metamodel!")
  1266. elif (bool_and(dict_in(pn_operations(), cmd), bool_not(bottom))):
  1267. // A model-specific operation, so execute that one
  1268. Element specific_op
  1269. specific_op = dict_read(pn_operations(), cmd)
  1270. specific_op(model)
  1271. else:
  1272. output("Unknown command; aborting")
  1273. output("Use command 'help' to get a list of available commands")
  1274. Element function initial_prompt():
  1275. output("Welcome to the Model Management Interface, running live on the Modelverse!")
  1276. output("Use 'help' command for a list of possible commands")
  1277. String command
  1278. Element root
  1279. Element metamodel
  1280. String name
  1281. Element my_model
  1282. String mm_name
  1283. root = create_metamodels()
  1284. while (True):
  1285. output("Please give your command.")
  1286. command = input()
  1287. if (command == "help"):
  1288. output("Currently no model is loaded, so your operations are limited to:")
  1289. output(" new -- Create a new model and save it for future use")
  1290. output(" load -- Load a previously made model")
  1291. output(" rename -- Rename a previously made model")
  1292. output(" delete -- Delete a previously made model")
  1293. output(" list -- Show a list of all stored models")
  1294. output(" help -- Show a list of possible commands")
  1295. elif (command == "new"):
  1296. output("Metamodel to instantiate?")
  1297. mm_name = input()
  1298. if (dict_in(root, mm_name)):
  1299. output("Name of model?")
  1300. name = input()
  1301. if (dict_in(root, name)):
  1302. output("Model exists; aborting")
  1303. else:
  1304. my_model = instantiate_model(root[mm_name])
  1305. dict_add(root, name, my_model)
  1306. petrinet_loaded(my_model)
  1307. else:
  1308. output("Unknown metamodel; aborting")
  1309. elif (command == "load"):
  1310. output("Model to load?")
  1311. name = input()
  1312. if (dict_in(root, name)):
  1313. my_model = root[name]
  1314. petrinet_loaded(my_model)
  1315. else:
  1316. output("Model not found; aborting")
  1317. elif (command == "list"):
  1318. Element keys
  1319. String m_menu_list
  1320. keys = dict_keys(root)
  1321. output("Found models:")
  1322. while (read_nr_out(keys) > 0):
  1323. m_menu_list = set_pop(keys)
  1324. output(((" " + m_menu_list) + " : ") + reverseNameLookup(root, root[m_menu_list]["metamodel"]))
  1325. elif (command == "delete"):
  1326. output("Model to delete?")
  1327. name = input()
  1328. if (dict_in(root, name)):
  1329. dict_delete(root, name)
  1330. output("Deleted!")
  1331. else:
  1332. output("Model not found; aborting")
  1333. elif (command == "rename"):
  1334. output("Old name?")
  1335. String old_name
  1336. old_name = input()
  1337. if (dict_in(root, old_name)):
  1338. output("New name?")
  1339. String new_name
  1340. new_name = input()
  1341. if (dict_in(root, new_name)):
  1342. output("Model exists; aborting")
  1343. else:
  1344. dict_add(root, new_name, root[old_name])
  1345. dict_delete(root, old_name)
  1346. output("Rename complete!")
  1347. else:
  1348. output("Model not found; aborting")
  1349. else:
  1350. output("Command not recognized, use 'help' for a list of possible commands")
  1351. Void function main():
  1352. //initial_prompt()
  1353. log("==========================================================================")
  1354. log("=== creating metamodels")
  1355. Element root
  1356. root = create_metamodels()
  1357. log("=== load instantiation of transformation metamodel")
  1358. Element transf
  1359. transf = petrinet_transformation(root)
  1360. log("=== load test1")
  1361. Element test1
  1362. test1 = test_simple_petrinet1(root)
  1363. log("=== check conformance of transformation")
  1364. log(conformance_scd(transf))
  1365. log("=== run transform")
  1366. tf_transform(transf, test1)
  1367. log("=== printing some places")
  1368. printNode(test1, test1["model"]["p1"])
  1369. printNode(test1, test1["model"]["p2"])
  1370. log("=== done")
  1371. log("==========================================================================")
  1372. return