pn_interface.alc 60 KB

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