pn_interface.alc 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502
  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. if( bool_not(is_physical_int(RandomNumberState))):
  518. RandomNumberState = 4 // xkcd.com/221/
  519. RandomNumberState = modulo((8121*RandomNumberState) + 28411, 134456)
  520. return modulo(RandomNumberState , (max-min)+1)+min
  521. Element function tf_executeARule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element, pivots : Element):
  522. //find LHS
  523. //TODO if no lhs (is this allowed to happen?) // or empty lhs
  524. Element tf_er_lhs
  525. tf_er_lhs = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "lhs"))
  526. tf_er_lhs = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_lhs)), tf_er_model, pivots)
  527. Integer nr_of_lhs_matches
  528. nr_of_lhs_matches = list_len(tf_er_lhs)
  529. //find NACs if at least one lhs is found (otherwise not needed)
  530. Integer nr_of_nac_matches
  531. nr_of_nac_matches = 0
  532. Element tf_er_nac
  533. tf_er_nac = create_node()
  534. if(nr_of_lhs_matches > 0):
  535. Element tf_er_nac_
  536. tf_er_nac_ = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "nac"))
  537. Element partial_nac_matches
  538. while (read_nr_out(tf_er_nac_) > 0):
  539. partial_nac_matches = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_nac_)), tf_er_model, pivots)
  540. while (read_nr_out(partial_nac_matches)>0):
  541. list_append(tf_er_nac, set_pop(partial_nac_matches))
  542. nr_of_nac_matches = list_len(tf_er_nac)
  543. //remove from lhs matches that share a node with a nac match
  544. //TODO if nac is not related to match (no plabels match)
  545. Element final_matches
  546. final_matches = mergeLHSNAC(tf_er_lhs, tf_er_nac)
  547. //extract pivots from the matches
  548. extractPivots(final_matches, pivots, tf_er_transformation, tf_er_model)
  549. //rhs part
  550. //create plabel_to_rhsnode
  551. Element RHS
  552. RHS = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, tf_er_transformation["metamodel"]["model"]["rhs"])
  553. if(read_nr_out(RHS) > 0):
  554. RHS = read_edge_dst(set_pop(RHS))
  555. Element metamodelTransf //transformation metamodel
  556. metamodelTransf = tf_er_transformation["metamodel"]["model"]
  557. Element post2ram // type of the post2ram edge
  558. post2ram = dict_read(metamodelTransf, "post2ram")
  559. post2ram = allOutgoingAssociationInstances(tf_er_transformation, RHS, post2ram)
  560. Element plabel_to_rhsnode //dict in the form plabel->node
  561. plabel_to_rhsnode = create_node()
  562. Element rhs_node
  563. Integer rhs_plabel
  564. while (integer_lt(0, list_len(post2ram))):
  565. rhs_node = read_edge_dst(set_pop(post2ram))
  566. rhs_plabel = read_attribute(tf_er_transformation, getName(tf_er_transformation, rhs_node), "plabel")
  567. dict_add(plabel_to_rhsnode,rhs_plabel, rhs_node)
  568. rhs_rewrite(final_matches ,plabel_to_rhsnode, tf_er_transformation, tf_er_model )
  569. return pivots
  570. Element function executeRuleBlock(transformation_model : Element,hostmodel:Element, ruleblock : Element, pivots:Element):
  571. //execute the correct ruletype
  572. //TODO define decent succes_value
  573. String typename
  574. typename = getTypeName(transformation_model, ruleblock)
  575. Boolean succes
  576. succes = False
  577. Element Rule
  578. if (typename == "RuleBlockRoot"):
  579. // do nothing
  580. log("start transformation")
  581. succes = True
  582. elif (typename == "ARule"):
  583. log("running arule")
  584. Rule = read_edge_dst(set_pop(allOutgoingAssociationInstances(transformation_model, ruleblock, transformation_model["metamodel"]["model"]["getrule"])))
  585. log(getName(transformation_model, Rule))
  586. pivots = tf_executeARule(transformation_model, Rule, hostmodel, pivots)
  587. succes = True
  588. elif (typename == "FRule"):
  589. log("running frule")
  590. Rule = read_edge_dst(set_pop(allOutgoingAssociationInstances(transformation_model, ruleblock, transformation_model["metamodel"]["model"]["getrule"])))
  591. log(getName(transformation_model, Rule))
  592. pivots = tf_executeFRule(transformation_model, Rule, hostmodel, pivots)
  593. succes = True
  594. else:
  595. log("RuleType is not supported yet")
  596. //Return the next
  597. Element next
  598. if succes:
  599. next = allOutgoingAssociationInstances(transformation_model, ruleblock, transformation_model["metamodel"]["model"]["next_onSucces"])
  600. else:
  601. next = allOutgoingAssociationInstances(transformation_model, ruleblock, transformation_model["metamodel"]["model"]["next_onFailure"])
  602. if (read_nr_out(next) == 0):
  603. log("No next defined")
  604. next = transformation_model
  605. else:
  606. next = read_edge_dst(set_pop(next))
  607. return next
  608. Element function tf_transform(tf_tf_transformation: Element, tf_tf_model: Element):
  609. //create a list of all rules
  610. Element ruleblock
  611. ruleblock = allInstances(tf_tf_transformation, tf_tf_transformation["metamodel"]["model"]["RuleBlockRoot"])
  612. if(read_nr_out(ruleblock) > 0):
  613. ruleblock = set_pop(ruleblock)
  614. Element pivots
  615. pivots = create_node()
  616. Boolean continue
  617. continue = True
  618. while (continue):
  619. ruleblock = executeRuleBlock(tf_tf_transformation,tf_tf_model, ruleblock, pivots)
  620. if(element_eq(ruleblock,tf_tf_transformation)):
  621. log("finished")
  622. continue = False
  623. else:
  624. log("root ruleblock not found")
  625. return 0
  626. Element function test_simple_petrinet1(root:Element):
  627. //create a petrinet for testing purposes
  628. // P1 -> T1 -> P2 -> T2
  629. // m:1 w:1 w:2 m:0 w:1
  630. // l1 l2 l3
  631. //////////////////////////////////
  632. //initialise an empty petrinet
  633. Element my_model
  634. my_model = instantiate_model(root["PetriNets"])
  635. dict_add(root, "pnt_test1", my_model)
  636. // init t1
  637. instantiate_node(my_model, "Transition", "t1")
  638. // init p1
  639. instantiate_node(my_model, "Place", "p1")
  640. instantiate_attribute(my_model, "p1","tokens",1)
  641. // init link1
  642. instantiate_link(my_model, "P2T", "p1_to_t1", "p1", "t1")
  643. instantiate_attribute(my_model, "p1_to_t1", "weight", 1)
  644. //init p2
  645. instantiate_node(my_model, "Place", "p2")
  646. instantiate_attribute(my_model, "p2","tokens",0)
  647. //init link2
  648. instantiate_link(my_model, "T2P", "t1_to_p2", "t1", "p2")
  649. instantiate_attribute(my_model, "t1_to_p2", "weight", 2)
  650. //init t2
  651. instantiate_node(my_model, "Transition", "t2")
  652. //init link3
  653. instantiate_link(my_model, "P2T", "p2_to_t2", "p2", "t2")
  654. instantiate_attribute(my_model, "p2_to_t2", "weight", 1)
  655. return my_model
  656. Element function petrinet_transformation(root: Element):
  657. // Create A transformation model for petrinets (useful for testing)
  658. //////////////////////////////////
  659. //initialise an empty transformation model for petrinet
  660. Element my_model
  661. my_model = instantiate_model(root["PetriNets_MTransformation"])
  662. define_inheritance(my_model, "l3")
  663. dict_add(root, "transf_petrinet_fire", my_model)
  664. ////////////////////////////
  665. // root node
  666. instantiate_node(my_model, "Transformation", "PetrinetFire")
  667. instantiate_attribute(my_model, "PetrinetFire", "name", "PetriNetFire")
  668. ////////////////////////////
  669. // rule: find transitions
  670. //rule: find_transitions
  671. instantiate_node(my_model, "Rule", "find_transitions")
  672. instantiate_attribute(my_model, "find_transitions", "name", "find_transitions")
  673. instantiate_attribute(my_model, "find_transitions", "precedence", 1)
  674. //connect to transformation
  675. instantiate_link(my_model, "transformation_to_rule", "", "PetrinetFire", "find_transitions")
  676. //precondition: lhs_precondition
  677. instantiate_node(my_model, "Precondition","lhs_precondition")
  678. //connect to rule
  679. instantiate_link(my_model, "lhs", "", "find_transitions", "lhs_precondition")
  680. //Transition_LHS: lhs_find_all
  681. instantiate_node(my_model, "Transition_LHS","lhs_find_all")
  682. instantiate_attribute(my_model, "lhs_find_all", "plabel", 1)
  683. instantiate_attribute(my_model, "lhs_find_all", "function", "always_true")
  684. instantiate_attribute(my_model, "lhs_find_all", "pivotOut", "enabled")
  685. instantiate_attribute(my_model, "lhs_find_all", "pivotIn", "")
  686. //connect to rule
  687. instantiate_link(my_model, "pre2ram", "", "lhs_precondition", "lhs_find_all")
  688. //precondition: nac_precondition
  689. instantiate_node(my_model, "Precondition","nac_precondition")
  690. //connect to rule
  691. instantiate_link(my_model, "nac", "", "find_transitions", "nac_precondition")
  692. //Transition_LHS: nac_transition_place_before
  693. instantiate_node(my_model, "Transition_LHS","nac_transition_before")
  694. instantiate_attribute(my_model, "nac_transition_before", "plabel", 1)
  695. instantiate_attribute(my_model, "nac_transition_before", "function", "always_true")
  696. instantiate_attribute(my_model, "nac_transition_before", "pivotOut", "")
  697. instantiate_attribute(my_model, "nac_transition_before", "pivotIn", "")
  698. //connect to rule
  699. instantiate_link(my_model, "pre2ram", "", "nac_precondition", "nac_transition_before")
  700. //Place_LHS: nac_place_before
  701. instantiate_node(my_model, "Place_LHS","nac_place_before")
  702. instantiate_attribute(my_model, "nac_place_before", "plabel", 2)
  703. instantiate_attribute(my_model, "nac_place_before", "function", "always_true")
  704. instantiate_attribute(my_model, "nac_place_before", "pivotOut", "")
  705. instantiate_attribute(my_model, "nac_place_before", "pivotIn", "")
  706. //connect to rule
  707. instantiate_link(my_model, "pre2ram", "", "nac_precondition", "nac_place_before")
  708. //P2T_LHS: nac_ft_p2t
  709. instantiate_link(my_model, "P2T_LHS", "nac_p2tlhs_before", "nac_place_before", "nac_transition_before")
  710. instantiate_attribute(my_model, "nac_p2tlhs_before", "plabel", 3)
  711. instantiate_attribute(my_model, "nac_p2tlhs_before", "function", "is_not_consumable")
  712. instantiate_attribute(my_model, "nac_p2tlhs_before", "pivotOut", "")
  713. instantiate_attribute(my_model, "nac_p2tlhs_before", "pivotIn", "")
  714. //connect to rule
  715. instantiate_link(my_model, "pre2ram", "", "nac_precondition", "nac_p2tlhs_before")
  716. ////////////////////////////
  717. // rule: consume tokens
  718. //rule: consume_tokens
  719. instantiate_node(my_model, "Rule", "consume_tokens")
  720. instantiate_attribute(my_model, "consume_tokens", "name", "consume_tokens")
  721. instantiate_attribute(my_model, "consume_tokens", "precedence", 2)
  722. //connect to transformation
  723. instantiate_link(my_model, "transformation_to_rule", "", "PetrinetFire", "consume_tokens")
  724. //precondition: lhs_precondition
  725. instantiate_node(my_model, "Precondition","ct_lhs_precondition")
  726. //connect to rule
  727. instantiate_link(my_model, "lhs", "", "consume_tokens", "ct_lhs_precondition")
  728. //Transition_LHS: ct_lhs_transition
  729. instantiate_node(my_model, "Transition_LHS","ct_lhs_transition")
  730. instantiate_attribute(my_model, "ct_lhs_transition", "plabel", 1)
  731. instantiate_attribute(my_model, "ct_lhs_transition", "function", "always_true")
  732. instantiate_attribute(my_model, "ct_lhs_transition", "pivotOut", "")
  733. instantiate_attribute(my_model, "ct_lhs_transition", "pivotIn", "enabled")
  734. //connect to rule
  735. instantiate_link(my_model, "pre2ram", "", "ct_lhs_precondition", "ct_lhs_transition")
  736. //Place_LHS: ct_lhs_place
  737. instantiate_node(my_model, "Place_LHS","ct_lhs_place")
  738. instantiate_attribute(my_model, "ct_lhs_place", "plabel", 2)
  739. instantiate_attribute(my_model, "ct_lhs_place", "function", "always_true")
  740. instantiate_attribute(my_model, "ct_lhs_place", "pivotOut", "")
  741. instantiate_attribute(my_model, "ct_lhs_place", "pivotIn", "")
  742. //connect to rule
  743. instantiate_link(my_model, "pre2ram", "", "ct_lhs_precondition", "ct_lhs_place")
  744. //P2T_LHS: ct_lhs_link
  745. instantiate_link(my_model, "P2T_LHS", "ct_lhs_link", "ct_lhs_place", "ct_lhs_transition")
  746. instantiate_attribute(my_model, "ct_lhs_link", "plabel", 3)
  747. instantiate_attribute(my_model, "ct_lhs_link", "function", "always_true")
  748. instantiate_attribute(my_model, "ct_lhs_link", "pivotOut", "")
  749. instantiate_attribute(my_model, "ct_lhs_link", "pivotIn", "")
  750. //connect to rule
  751. instantiate_link(my_model, "pre2ram", "", "ct_lhs_precondition", "ct_lhs_link")
  752. //precondition: rhs_postcondition
  753. instantiate_node(my_model, "Postcondition","ct_rhs_postcondition")
  754. //connect to rule
  755. instantiate_link(my_model, "rhs", "", "consume_tokens", "ct_rhs_postcondition")
  756. //Transition_RHS: ct_rhs_transition
  757. instantiate_node(my_model, "Transition_RHS","ct_rhs_transition")
  758. instantiate_attribute(my_model, "ct_rhs_transition", "plabel", 1)
  759. instantiate_attribute(my_model, "ct_rhs_transition", "function", "do_nothing")
  760. instantiate_attribute(my_model, "ct_rhs_transition", "pivotOut", "")
  761. instantiate_attribute(my_model, "ct_rhs_transition", "pivotIn", "")
  762. //connect to rule
  763. instantiate_link(my_model, "post2ram", "", "ct_rhs_postcondition", "ct_rhs_transition")
  764. //Place_RHS: ct_rhs_place
  765. instantiate_node(my_model, "Place_RHS","ct_rhs_place")
  766. instantiate_attribute(my_model, "ct_rhs_place", "plabel", 2)
  767. instantiate_attribute(my_model, "ct_rhs_place", "function", "do_nothing")
  768. instantiate_attribute(my_model, "ct_rhs_place", "pivotOut", "")
  769. instantiate_attribute(my_model, "ct_rhs_place", "pivotIn", "")
  770. //connect to rule
  771. instantiate_link(my_model, "post2ram", "", "ct_rhs_postcondition", "ct_rhs_place")
  772. //P2T_RHS: ct_rhs_link
  773. instantiate_link(my_model, "P2T_RHS", "ct_rhs_link", "ct_rhs_place", "ct_rhs_transition")
  774. instantiate_attribute(my_model, "ct_rhs_link", "plabel", 3)
  775. instantiate_attribute(my_model, "ct_rhs_link", "function", "remove_tokens")
  776. instantiate_attribute(my_model, "ct_rhs_link", "pivotOut", "")
  777. instantiate_attribute(my_model, "ct_rhs_link", "pivotIn", "")
  778. //connect to rule
  779. instantiate_link(my_model, "post2ram", "", "ct_rhs_postcondition", "ct_rhs_link")
  780. ////////////////////////////
  781. // rule: produce tokens
  782. //rule: produce_tokens
  783. instantiate_node(my_model, "Rule", "produce_tokens")
  784. instantiate_attribute(my_model, "produce_tokens", "name", "produce_tokens")
  785. instantiate_attribute(my_model, "produce_tokens", "precedence", 3)
  786. //connect to transformation
  787. instantiate_link(my_model, "transformation_to_rule", "", "PetrinetFire", "produce_tokens")
  788. //precondition: lhs_precondition
  789. instantiate_node(my_model, "Precondition","pt_lhs_precondition")
  790. //connect to rule
  791. instantiate_link(my_model, "lhs", "", "produce_tokens", "pt_lhs_precondition")
  792. //Transition_LHS: pt_lhs_transition
  793. instantiate_node(my_model, "Transition_LHS","pt_lhs_transition")
  794. instantiate_attribute(my_model, "pt_lhs_transition", "plabel", 1)
  795. instantiate_attribute(my_model, "pt_lhs_transition", "function", "always_true")
  796. instantiate_attribute(my_model, "pt_lhs_transition", "pivotOut", "")
  797. instantiate_attribute(my_model, "pt_lhs_transition", "pivotIn", "enabled")
  798. //connect to rule
  799. instantiate_link(my_model, "pre2ram", "", "pt_lhs_precondition", "pt_lhs_transition")
  800. //Place_LHS: pt_lhs_place
  801. instantiate_node(my_model, "Place_LHS","pt_lhs_place")
  802. instantiate_attribute(my_model, "pt_lhs_place", "plabel", 2)
  803. instantiate_attribute(my_model, "pt_lhs_place", "function", "always_true")
  804. instantiate_attribute(my_model, "pt_lhs_place", "pivotOut", "")
  805. instantiate_attribute(my_model, "pt_lhs_place", "pivotIn", "")
  806. //connect to rule
  807. instantiate_link(my_model, "pre2ram", "", "pt_lhs_precondition", "pt_lhs_place")
  808. //P2T_LHS: pt_lhs_link
  809. instantiate_link(my_model, "T2P_LHS", "pt_lhs_link", "pt_lhs_transition", "pt_lhs_place")
  810. instantiate_attribute(my_model, "pt_lhs_link", "plabel", 3)
  811. instantiate_attribute(my_model, "pt_lhs_link", "function", "always_true")
  812. instantiate_attribute(my_model, "pt_lhs_link", "pivotOut", "")
  813. instantiate_attribute(my_model, "pt_lhs_link", "pivotIn", "")
  814. //connect to rule
  815. instantiate_link(my_model, "pre2ram", "", "pt_lhs_precondition", "pt_lhs_link")
  816. //precondition: rhs_postcondition
  817. instantiate_node(my_model, "Postcondition","pt_rhs_postcondition")
  818. //connect to rule
  819. instantiate_link(my_model, "rhs", "", "produce_tokens", "pt_rhs_postcondition")
  820. //Transition_RHS: pt_rhs_transition
  821. instantiate_node(my_model, "Transition_RHS","pt_rhs_transition")
  822. instantiate_attribute(my_model, "pt_rhs_transition", "plabel", 1)
  823. instantiate_attribute(my_model, "pt_rhs_transition", "function", "do_nothing")
  824. instantiate_attribute(my_model, "pt_rhs_transition", "pivotOut", "")
  825. instantiate_attribute(my_model, "pt_rhs_transition", "pivotIn", "")
  826. //connect to rule
  827. instantiate_link(my_model, "post2ram", "", "pt_rhs_postcondition", "pt_rhs_transition")
  828. //Place_RHS: pt_rhs_place
  829. instantiate_node(my_model, "Place_RHS","pt_rhs_place")
  830. instantiate_attribute(my_model, "pt_rhs_place", "plabel", 2)
  831. instantiate_attribute(my_model, "pt_rhs_place", "function", "do_nothing")
  832. instantiate_attribute(my_model, "pt_rhs_place", "pivotOut", "")
  833. instantiate_attribute(my_model, "pt_rhs_place", "pivotIn", "")
  834. //connect to rule
  835. instantiate_link(my_model, "post2ram", "", "pt_rhs_postcondition", "pt_rhs_place")
  836. //P2T_RHS: ct_rhs_link
  837. instantiate_link(my_model, "T2P_RHS", "pt_rhs_link", "pt_rhs_transition", "pt_rhs_place")
  838. instantiate_attribute(my_model, "pt_rhs_link", "plabel", 3)
  839. instantiate_attribute(my_model, "pt_rhs_link", "function", "add_tokens")
  840. instantiate_attribute(my_model, "pt_rhs_link", "pivotOut", "")
  841. instantiate_attribute(my_model, "pt_rhs_link", "pivotIn", "")
  842. //connect to rule
  843. instantiate_link(my_model, "post2ram", "", "pt_rhs_postcondition", "pt_rhs_link")
  844. ////////////////////////////
  845. // rule ordering part
  846. //start node
  847. instantiate_node(my_model, "RuleBlockRoot", "rule_root")
  848. //ARule: enabled
  849. instantiate_node(my_model, "ARule", "arule1")
  850. //connect to startnode
  851. instantiate_link(my_model, "next_onSucces", "", "rule_root", "arule1")
  852. //connect to rule
  853. instantiate_link(my_model, "getrule","", "arule1", "find_transitions")
  854. //FRule: consume
  855. instantiate_node(my_model, "FRule", "frule2")
  856. //connect to arule1
  857. instantiate_link(my_model, "next_onSucces", "", "arule1", "frule2")
  858. //connect to rule
  859. instantiate_link(my_model, "getrule","", "frule2", "consume_tokens")
  860. //Frule: produce
  861. instantiate_node(my_model, "FRule", "frule3")
  862. //connect to frule2
  863. instantiate_link(my_model, "next_onSucces", "", "frule2", "frule3")
  864. //connect to rule
  865. instantiate_link(my_model, "getrule","", "frule3", "produce_tokens")
  866. ////////////////////////////
  867. // semantic checks
  868. Element semantic_checks
  869. semantic_checks = create_node()
  870. dict_add(semantic_checks, "always_true", always_true)
  871. dict_add(semantic_checks, "is_not_consumable", is_not_consumable)
  872. dict_add(my_model, "semantic_checks", semantic_checks)
  873. Element actions
  874. actions = create_node()
  875. dict_add(actions, "do_nothing", do_nothing)
  876. dict_add(actions, "add_tokens", add_tokens)
  877. dict_add(actions, "remove_tokens", remove_tokens)
  878. dict_add(my_model, "actions", actions)
  879. return my_model
  880. Boolean function is_not_consumable(model : Element, matched_node : Element):
  881. //get place before
  882. Element place_before
  883. place_before = read_edge_src(matched_node)
  884. //get tokens from place
  885. Integer tokens
  886. tokens = read_attribute(model, getName(model, place_before), "tokens")
  887. //get weight from matched_node
  888. Integer weight
  889. weight = read_attribute(model, getName(model, matched_node), "weight")
  890. return weight > tokens
  891. Boolean function always_true(model : Element, self : Element):
  892. return True
  893. Element function do_nothing(model: Element, self : Element):
  894. return 0
  895. Element function remove_tokens(model:Element, self: Element):
  896. //get place before
  897. Element place_before
  898. place_before = read_edge_src(self)
  899. //get tokens from place
  900. Integer tokens
  901. tokens = read_attribute(model, getName(model, place_before), "tokens")
  902. //get weight from matched_node
  903. Integer weight
  904. weight = read_attribute(model, getName(model, self), "weight")
  905. //rewrite tokens
  906. unset_attribute(model, getName(model, place_before), "tokens")
  907. instantiate_attribute(model, getName(model, place_before), "tokens", tokens-weight)
  908. return 0
  909. Element function add_tokens(model:Element, self: Element):
  910. //get place before
  911. Element place_after
  912. place_after = read_edge_dst(self)
  913. //get tokens from place
  914. Integer tokens
  915. tokens = read_attribute(model, getName(model, place_after), "tokens")
  916. //get weight from matched_node
  917. Integer weight
  918. weight = read_attribute(model, getName(model, self), "weight")
  919. //rewrite tokens
  920. unset_attribute(model, getName(model, place_after), "tokens")
  921. instantiate_attribute(model, getName(model, place_after), "tokens", tokens+weight)
  922. return 0
  923. Element function pn_operations():
  924. Element ops
  925. ops = create_node()
  926. dict_add(ops, "fire", petrinet_fire)
  927. dict_add(ops, "enabled", petrinet_enabled)
  928. return ops
  929. Element function petrinet_enabled(model : Element):
  930. Element set_enabled
  931. set_enabled = petrinet_enabled_set(model)
  932. output("Enabled transitions:")
  933. while (0 < read_nr_out(set_enabled)):
  934. output(getName(model, set_pop(set_enabled)))
  935. return model
  936. Element function petrinet_enabled_set(model : Element):
  937. Element all_transitions
  938. all_transitions = allInstances(model, model["metamodel"]["model"]["Transition"])
  939. Element enabled_transitions
  940. enabled_transitions = create_node()
  941. Element under_study
  942. Element in_arcs
  943. Element arc_under_study
  944. Boolean enabled
  945. while (0 < read_nr_out(all_transitions)):
  946. under_study = set_pop(all_transitions)
  947. enabled = True
  948. // Find all incoming transitions
  949. in_arcs = allIncomingAssociationInstances(model, under_study, model["metamodel"]["model"]["P2T"])
  950. while (0 < read_nr_out(in_arcs)):
  951. arc_under_study = set_pop(in_arcs)
  952. Integer present_tokens
  953. Integer required_tokens
  954. required_tokens = read_attribute(model, getName(model, arc_under_study), "weight")
  955. present_tokens = read_attribute(model, getName(model, read_edge_src(arc_under_study)), "tokens")
  956. if (present_tokens < required_tokens):
  957. // Less tokens than required, so disable the transition completely
  958. enabled = False
  959. if (enabled):
  960. set_add(enabled_transitions, under_study)
  961. return enabled_transitions
  962. Element function petrinet_fire(model : Element):
  963. output("Transition to fire?")
  964. Element transition
  965. transition = input()
  966. if (dict_in(model["model"], transition)):
  967. transition = model["model"][transition]
  968. if (set_in(petrinet_enabled_set(model), transition)):
  969. Element workset
  970. Element working_place
  971. Element working_arc
  972. Integer new_value
  973. // Consume tokens
  974. workset = allIncomingAssociationInstances(model, transition, model["metamodel"]["model"]["P2T"])
  975. while (0 < read_nr_out(workset)):
  976. working_arc = set_pop(workset)
  977. working_place = read_edge_src(working_arc)
  978. new_value = integer_subtraction(read_attribute(model, getName(model, working_place), "tokens"), read_attribute(model, getName(model, working_arc), "weight"))
  979. unset_attribute(model, getName(model, working_place), "tokens")
  980. instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
  981. output(((" " + getName(model, working_place)) + ": ") + cast_i2s(read_attribute(model, getName(model, working_place), "tokens")))
  982. // Add tokens
  983. workset = allOutgoingAssociationInstances(model, transition, model["metamodel"]["model"]["T2P"])
  984. while (0 < read_nr_out(workset)):
  985. working_arc = set_pop(workset)
  986. working_place = read_edge_dst(working_arc)
  987. new_value = integer_addition(read_attribute(model, getName(model, working_place), "tokens"), read_attribute(model, getName(model, working_arc), "weight"))
  988. unset_attribute(model, getName(model, working_place), "tokens")
  989. instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
  990. output(((" " + getName(model, working_place)) + ": ") + cast_i2s(read_attribute(model, getName(model, working_place), "tokens")))
  991. output("Transition fired!")
  992. else:
  993. output("Cannot fire if not enabled; aborting")
  994. else:
  995. output("Unknown transition; aborting")
  996. return model
  997. Element function petrinet_loaded(model : Element):
  998. String cmd
  999. Element attr_list_pn
  1000. Element attr_keys_pn
  1001. String attr_key_pn
  1002. Element metamodel_element_pn
  1003. String typename
  1004. Boolean bottom
  1005. Element other_metamodel
  1006. bottom = False
  1007. other_metamodel = create_node()
  1008. dict_add(other_metamodel, "model", model["model"])
  1009. dict_add(other_metamodel, "type_mapping", create_node())
  1010. dict_add(other_metamodel, "metamodel", import_node("models/LTM_bottom"))
  1011. dict_add(other_metamodel, "inheritance", other_metamodel["metamodel"]["model"]["__Inheritance"])
  1012. output("Model loaded, ready for commands!")
  1013. output("Use 'help' command for a list of possible commands")
  1014. while (True):
  1015. output("Please give your command.")
  1016. cmd = input()
  1017. if (cmd == "help"):
  1018. output("Generic model operations:")
  1019. output(" instantiate -- Create a new model element")
  1020. output(" delete -- Delete an existing element")
  1021. output(" attr_add -- Add an attribute to an element")
  1022. output(" attr_del -- Delete an attribute of an element")
  1023. output(" rename -- Rename an existing element")
  1024. output(" modify -- Modify the attributes of an element")
  1025. output(" list -- Prints the list of elements in the model")
  1026. output(" types -- Prints the list of elements that can be instantiated")
  1027. output(" read -- Prints the current state of a model element")
  1028. output(" verify -- Check whether the model conforms to the metamodel")
  1029. output(" retype -- Change the type of an element")
  1030. output(" switch -- Switch between conformance bottom and the linguistic metamodel")
  1031. output(" exit -- Unload the model and go back to the loading prompt")
  1032. if (bool_not(bottom)):
  1033. output("Model-specific operations:")
  1034. Element specific_ops
  1035. specific_ops = dict_keys(pn_operations())
  1036. String specific_op
  1037. while (0 < dict_len(specific_ops)):
  1038. specific_op = set_pop(specific_ops)
  1039. output(" " + specific_op)
  1040. elif (cmd == "exit"):
  1041. return model
  1042. elif (cmd == "instantiate"):
  1043. String mm_type_name
  1044. output("Type to instantiate?")
  1045. mm_type_name = input()
  1046. if (dict_in(model["metamodel"]["model"], mm_type_name)):
  1047. String element_name
  1048. output("Name of new element?")
  1049. element_name = input()
  1050. if (dict_in(model["model"], element_name)):
  1051. output("Element already exists; aborting")
  1052. else:
  1053. if (is_edge(model["metamodel"]["model"][mm_type_name])):
  1054. output("Source name?")
  1055. String src_name
  1056. src_name = input()
  1057. if (dict_in(model["model"], src_name)):
  1058. output("Destination name?")
  1059. String dst_name
  1060. dst_name = input()
  1061. if (dict_in(model["model"], dst_name)):
  1062. instantiate_link(model, mm_type_name, element_name, src_name, dst_name)
  1063. if (dict_in(model["model"], element_name)):
  1064. output("Instantiation successful!")
  1065. else:
  1066. output("Instantiation error!")
  1067. else:
  1068. output("Unknown destination; aborting")
  1069. else:
  1070. output("Unknown source; aborting")
  1071. else:
  1072. instantiate_node(model, mm_type_name, element_name)
  1073. if (dict_in(model["model"], element_name)):
  1074. output("Instantiation successful!")
  1075. else:
  1076. output("Instantiation error!")
  1077. else:
  1078. output("Unknown type specified; aborting")
  1079. elif (cmd == "modify"):
  1080. String model_name
  1081. output("Element to modify?")
  1082. model_name = input()
  1083. if (dict_in(model["model"], model_name)):
  1084. Element attrs
  1085. attrs = getAttributeList(model, model_name)
  1086. String attr_name
  1087. output("Attribute to modify?")
  1088. attr_name = input()
  1089. if (set_in(dict_keys(attrs), attr_name)):
  1090. output("New value?")
  1091. unset_attribute(model, model_name, attr_name)
  1092. instantiate_attribute(model, model_name, attr_name, input())
  1093. output("Modified!")
  1094. else:
  1095. output("No such attribute!")
  1096. else:
  1097. output("No such model!")
  1098. elif (cmd == "attr_add"):
  1099. String model_name
  1100. output("Which model do you want to assign an attribute to?")
  1101. model_name = input()
  1102. if (dict_in(model["model"], model_name)):
  1103. Element attrs
  1104. attrs = getAttributeList(model, model_name)
  1105. String attr_name
  1106. output("Which attribute do you wish to assign?")
  1107. attr_name = input()
  1108. if (set_in(dict_keys(attrs), attr_name)):
  1109. output("Value of attribute?")
  1110. instantiate_attribute(model, model_name, attr_name, input())
  1111. output("Added attribute!")
  1112. else:
  1113. output("No such attribute!")
  1114. else:
  1115. output("No such model!")
  1116. elif (cmd == "attr_del"):
  1117. String model_name
  1118. output("Which model do you want to remove an attribute of?")
  1119. model_name = input()
  1120. if (dict_in(model["model"], model_name)):
  1121. Element attrs
  1122. attrs = getAttributeList(model, model_name)
  1123. output(print_dict(attrs))
  1124. String attr_name
  1125. output("Which attribute do you want to delete?")
  1126. attr_name = input()
  1127. if (set_in(dict_keys(attrs), attr_name)):
  1128. unset_attribute(model, model_name, attr_name)
  1129. else:
  1130. output("No such attribute!")
  1131. else:
  1132. output("No such model!")
  1133. elif (cmd == "delete"):
  1134. output("What is the name of the element you want to delete?")
  1135. cmd = input()
  1136. if (dict_in(model["model"], cmd)):
  1137. model_delete_element(model, cmd)
  1138. output("Deleted!")
  1139. else:
  1140. output("No such element; aborting")
  1141. elif (cmd == "rename"):
  1142. output("Old name?")
  1143. String old_name_e
  1144. old_name_e = input()
  1145. if (dict_in(model["model"], old_name_e)):
  1146. output("New name?")
  1147. String new_name_e
  1148. new_name_e = input()
  1149. if (dict_in(model["model"], new_name_e)):
  1150. output("New name already used; aborting")
  1151. else:
  1152. dict_add(model["model"], new_name_e, model["model"][old_name_e])
  1153. dict_delete(model["model"], old_name_e)
  1154. output("Rename complete!")
  1155. else:
  1156. output("Unknown element; aborting")
  1157. elif (cmd == "list"):
  1158. Element keys_m
  1159. keys_m = dict_keys(model["model"])
  1160. output("List of all elements:")
  1161. String v_m
  1162. while (read_nr_out(keys_m) > 0):
  1163. v_m = set_pop(keys_m)
  1164. // Filter out anonymous objects
  1165. typename = getName(model["metamodel"], dict_read_node(model["type_mapping"], model["model"][v_m]))
  1166. if (bool_not(string_startswith(v_m, "__"))):
  1167. output(((" " + v_m) + " : ") + typename)
  1168. elif (cmd == "read"):
  1169. output("Element to read?")
  1170. cmd = input()
  1171. if (dict_in(model["model"], cmd)):
  1172. Element read_elem
  1173. read_elem = model["model"][cmd]
  1174. metamodel_element_pn = dict_read_node(model["type_mapping"], read_elem)
  1175. output("Name: " + cmd)
  1176. output("Type: " + getName(model["metamodel"], metamodel_element_pn))
  1177. if (is_edge(read_elem)):
  1178. output("Source: " + getName(model, read_edge_src(read_elem)))
  1179. output("Destination: " + getName(model, read_edge_dst(read_elem)))
  1180. if (cast_v2s(read_elem) != "None"):
  1181. output("Value: " + cast_v2s(read_elem))
  1182. output("Defines attributes:")
  1183. attr_list_pn = getInstantiatableAttributes(model, read_elem)
  1184. attr_keys_pn = dict_keys(attr_list_pn)
  1185. while (0 < read_nr_out(attr_keys_pn)):
  1186. attr_key_pn = set_pop(attr_keys_pn)
  1187. output((((" " + attr_key_pn) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])))
  1188. output("Attributes:")
  1189. attr_list_pn = getAttributeList(model, cmd)
  1190. attr_keys_pn = dict_keys(attr_list_pn)
  1191. while (0 < read_nr_out(attr_keys_pn)):
  1192. attr_key_pn = set_pop(attr_keys_pn)
  1193. 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)))
  1194. else:
  1195. output("Unknown element; aborting")
  1196. elif (cmd == "verify"):
  1197. output(conformance_scd(model))
  1198. elif (cmd == "types"):
  1199. Element keys_t
  1200. keys_t = dict_keys(model["metamodel"]["model"])
  1201. output("List of types:")
  1202. String v_t
  1203. while (read_nr_out(keys_t) > 0):
  1204. v_t = set_pop(keys_t)
  1205. if (bool_not(string_startswith(v_t, "__"))):
  1206. output(string_join((" " + v_t) + " : ", getName(model["metamodel"]["metamodel"], dict_read_node(model["metamodel"]["type_mapping"], model["metamodel"]["model"][v_t]))))
  1207. elif (cmd == "retype"):
  1208. output("Element to retype?")
  1209. String elementname
  1210. elementname = input()
  1211. if (dict_in(model["model"], elementname)):
  1212. output("New type")
  1213. typename = input()
  1214. if (dict_in(model["metamodel"]["model"], typename)):
  1215. // OK, do the retyping
  1216. // First try removing the previous type if it exists
  1217. dict_delete(model["type_mapping"], model["model"][elementname])
  1218. // Now add the new type
  1219. dict_add(model["type_mapping"], model["model"][elementname], model["metamodel"]["model"][typename])
  1220. output("Retyped!")
  1221. else:
  1222. output("Unknown type; aborting")
  1223. else:
  1224. output("Unknown element; aborting")
  1225. elif (cmd == "switch"):
  1226. bottom = bool_not(bottom)
  1227. Element tmp_model
  1228. tmp_model = model
  1229. model = other_metamodel
  1230. other_metamodel = tmp_model
  1231. if (bottom):
  1232. // The type mapping we are using is probably not complete for our model
  1233. // so we completely recreate it from the model we have.
  1234. output("Switching to conformance bottom mode!")
  1235. generate_bottom_type_mapping(model)
  1236. else:
  1237. // We already switched the models and such, so we are already done!
  1238. output("Switching to linguistic metamodel!")
  1239. elif (bool_and(dict_in(pn_operations(), cmd), bool_not(bottom))):
  1240. // A model-specific operation, so execute that one
  1241. Element specific_op
  1242. specific_op = dict_read(pn_operations(), cmd)
  1243. specific_op(model)
  1244. else:
  1245. output("Unknown command; aborting")
  1246. output("Use command 'help' to get a list of available commands")
  1247. Element function initial_prompt():
  1248. output("Welcome to the Model Management Interface, running live on the Modelverse!")
  1249. output("Use 'help' command for a list of possible commands")
  1250. String command
  1251. Element root
  1252. Element metamodel
  1253. String name
  1254. Element my_model
  1255. String mm_name
  1256. root = create_metamodels()
  1257. while (True):
  1258. output("Please give your command.")
  1259. command = input()
  1260. if (command == "help"):
  1261. output("Currently no model is loaded, so your operations are limited to:")
  1262. output(" new -- Create a new model and save it for future use")
  1263. output(" load -- Load a previously made model")
  1264. output(" rename -- Rename a previously made model")
  1265. output(" delete -- Delete a previously made model")
  1266. output(" list -- Show a list of all stored models")
  1267. output(" help -- Show a list of possible commands")
  1268. elif (command == "new"):
  1269. output("Metamodel to instantiate?")
  1270. mm_name = input()
  1271. if (dict_in(root, mm_name)):
  1272. output("Name of model?")
  1273. name = input()
  1274. if (dict_in(root, name)):
  1275. output("Model exists; aborting")
  1276. else:
  1277. my_model = instantiate_model(root[mm_name])
  1278. dict_add(root, name, my_model)
  1279. petrinet_loaded(my_model)
  1280. else:
  1281. output("Unknown metamodel; aborting")
  1282. elif (command == "load"):
  1283. output("Model to load?")
  1284. name = input()
  1285. if (dict_in(root, name)):
  1286. my_model = root[name]
  1287. petrinet_loaded(my_model)
  1288. else:
  1289. output("Model not found; aborting")
  1290. elif (command == "list"):
  1291. Element keys
  1292. String m_menu_list
  1293. keys = dict_keys(root)
  1294. output("Found models:")
  1295. while (read_nr_out(keys) > 0):
  1296. m_menu_list = set_pop(keys)
  1297. output(((" " + m_menu_list) + " : ") + reverseNameLookup(root, root[m_menu_list]["metamodel"]))
  1298. elif (command == "delete"):
  1299. output("Model to delete?")
  1300. name = input()
  1301. if (dict_in(root, name)):
  1302. dict_delete(root, name)
  1303. output("Deleted!")
  1304. else:
  1305. output("Model not found; aborting")
  1306. elif (command == "rename"):
  1307. output("Old name?")
  1308. String old_name
  1309. old_name = input()
  1310. if (dict_in(root, old_name)):
  1311. output("New name?")
  1312. String new_name
  1313. new_name = input()
  1314. if (dict_in(root, new_name)):
  1315. output("Model exists; aborting")
  1316. else:
  1317. dict_add(root, new_name, root[old_name])
  1318. dict_delete(root, old_name)
  1319. output("Rename complete!")
  1320. else:
  1321. output("Model not found; aborting")
  1322. else:
  1323. output("Command not recognized, use 'help' for a list of possible commands")
  1324. Void function main():
  1325. //initial_prompt()
  1326. log("==========================================================================")
  1327. log("=== creating metamodels")
  1328. Element root
  1329. root = create_metamodels()
  1330. log("=== load instantiation of transformation metamodel")
  1331. Element transf
  1332. transf = petrinet_transformation(root)
  1333. log("=== load test1")
  1334. Element test1
  1335. test1 = test_simple_petrinet1(root)
  1336. log("=== check conformance of transformation")
  1337. log(conformance_scd(transf))
  1338. log("=== run transform")
  1339. tf_transform(transf, test1)
  1340. log("=== printing some places")
  1341. printNode(test1, test1["model"]["p1"])
  1342. printNode(test1, test1["model"]["p2"])
  1343. log("=== done")
  1344. log("==========================================================================")
  1345. return