pn_interface.alc 59 KB

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