|
|
@@ -76,8 +76,9 @@ Element function printNode(tf_pn_model: Element, tf_pn_node: Element):
|
|
|
log(read_attribute(tf_pn_model, tf_pn_node_name, tf_pn_attributename))
|
|
|
return 0
|
|
|
|
|
|
+Element pivots
|
|
|
|
|
|
-Boolean function node_match(transf_model : Element, transf_elem : Element, host_model : Element, host_elem : Element, pivots : Element):
|
|
|
+Boolean function node_match(transf_model : Element, transf_elem : Element, host_model : Element, host_elem : Element):
|
|
|
|
|
|
//type equality
|
|
|
String type1
|
|
|
@@ -252,9 +253,6 @@ Element function new_SearchState(OldSearchState : Element, TransfModel : Element
|
|
|
// copy pattern_size
|
|
|
dict_add(nss, "pattern_size", OldSearchState["pattern_size"])
|
|
|
|
|
|
- //copy pivots
|
|
|
- dict_add(nss, "pivots",OldSearchState["pivots"])
|
|
|
-
|
|
|
return nss
|
|
|
|
|
|
Element function transf_vf2(SearchState: Element, transf_m : Element, host_m : Element):
|
|
|
@@ -298,7 +296,7 @@ Element function transf_vf2(SearchState: Element, transf_m : Element, host_m : E
|
|
|
while (index2 < list_len(host_list)):
|
|
|
host_node = list_read(host_list, index2)
|
|
|
index2= index2 + 1
|
|
|
- if(node_match(transf_m, pattern_node, host_m, host_node, SearchState["pivots"])):
|
|
|
+ if(node_match(transf_m, pattern_node, host_m, host_node)):
|
|
|
nss = new_SearchState(SearchState, transf_m, pattern_node, host_m, host_node)
|
|
|
nss = transf_vf2(nss, transf_m, host_m)
|
|
|
dict_delete(SearchState, "matches")
|
|
|
@@ -311,7 +309,7 @@ Element function transf_vf2(SearchState: Element, transf_m : Element, host_m : E
|
|
|
while (index2 < list_len(host_list)):
|
|
|
host_node = list_read(host_list, index2)
|
|
|
index2= index2 + 1
|
|
|
- if(node_match(transf_m, pattern_node, host_m, host_node, SearchState["pivots"])):
|
|
|
+ if(node_match(transf_m, pattern_node, host_m, host_node)):
|
|
|
nss = new_SearchState(SearchState, transf_m, pattern_node, host_m, host_node)
|
|
|
nss = transf_vf2(nss, transf_m, host_m)
|
|
|
dict_delete(SearchState, "matches")
|
|
|
@@ -324,7 +322,7 @@ Element function transf_vf2(SearchState: Element, transf_m : Element, host_m : E
|
|
|
while (index2 < list_len(host_list)):
|
|
|
host_node = list_read(host_list, index2)
|
|
|
index2= index2 + 1
|
|
|
- if(node_match(transf_m, pattern_node, host_m, host_node, SearchState["pivots"])):
|
|
|
+ if(node_match(transf_m, pattern_node, host_m, host_node)):
|
|
|
nss = new_SearchState(SearchState, transf_m, pattern_node, host_m, host_node)
|
|
|
nss = transf_vf2(nss, transf_m, host_m)
|
|
|
dict_delete(SearchState, "matches")
|
|
|
@@ -335,7 +333,7 @@ Element function transf_vf2(SearchState: Element, transf_m : Element, host_m : E
|
|
|
|
|
|
|
|
|
// given a pattern, this function will return all matches in a model
|
|
|
-Element function tf_matchAll(tf_ma_transformation: Element, tf_ma_pattern : Element, tf_ma_model: Element, pivots:Element ):
|
|
|
+Element function tf_matchAll(tf_ma_transformation: Element, tf_ma_pattern : Element, tf_ma_model: Element ):
|
|
|
|
|
|
//find all nodes in the pattern
|
|
|
|
|
|
@@ -380,7 +378,6 @@ Element function tf_matchAll(tf_ma_transformation: Element, tf_ma_pattern : Elem
|
|
|
dict_add(SearchState, "V_pattern", tf_ma_ramified_nodes)
|
|
|
dict_add(SearchState, "V_host", host_nodes)
|
|
|
dict_add(SearchState, "pattern_size", list_len(tf_ma_ramified_nodes))
|
|
|
- dict_add(SearchState, "pivots", pivots)
|
|
|
|
|
|
//call vf2 for the matching
|
|
|
|
|
|
@@ -414,7 +411,7 @@ Element function mergeLHSNAC(tf_er_lhs : Element, tf_er_nac: Element):
|
|
|
list_append(final_matches, lhs_match)
|
|
|
return final_matches
|
|
|
|
|
|
-Element function extractPivots(final_matches : Element, pivots: Element, tf_er_transformation : Element, tf_er_model : Element):
|
|
|
+Element function extractPivots(final_matches : Element, tf_er_transformation : Element, tf_er_model : Element):
|
|
|
Integer match_index
|
|
|
match_index = 0
|
|
|
Element pattern_match_node
|
|
|
@@ -510,13 +507,15 @@ Element function rhs_rewrite(final_matches : Element,plabel_to_rhsnode:Element,
|
|
|
log("unsupported metatype in rhs")
|
|
|
return 0
|
|
|
|
|
|
-Element function tf_executeFRule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element, pivots : Element):
|
|
|
+Element function tf_executeFRule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element):
|
|
|
|
|
|
//find LHS
|
|
|
//TODO if no lhs (is this allowed to happen?) // or empty lhs
|
|
|
Element tf_er_lhs
|
|
|
tf_er_lhs = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "lhs"))
|
|
|
- tf_er_lhs = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_lhs)), tf_er_model, pivots)
|
|
|
+ Integer nr_of_lhs_nodes
|
|
|
+ nr_of_lhs_nodes = read_nr_out(tf_er_lhs)
|
|
|
+ tf_er_lhs = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_lhs)), tf_er_model)
|
|
|
Integer nr_of_lhs_matches
|
|
|
nr_of_lhs_matches = list_len(tf_er_lhs)
|
|
|
|
|
|
@@ -530,18 +529,28 @@ Element function tf_executeFRule(tf_er_transformation: Element,tf_er_rule: Eleme
|
|
|
tf_er_nac_ = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "nac"))
|
|
|
Element partial_nac_matches
|
|
|
while (read_nr_out(tf_er_nac_) > 0):
|
|
|
- partial_nac_matches = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_nac_)), tf_er_model, pivots)
|
|
|
+ partial_nac_matches = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_nac_)), tf_er_model)
|
|
|
while (read_nr_out(partial_nac_matches)>0):
|
|
|
list_append(tf_er_nac, set_pop(partial_nac_matches))
|
|
|
nr_of_nac_matches = list_len(tf_er_nac)
|
|
|
-
|
|
|
+
|
|
|
+ if( nr_of_lhs_nodes == 0):
|
|
|
+ if (nr_of_nac_matches == 0):
|
|
|
+ return True
|
|
|
+ else:
|
|
|
+ return False
|
|
|
+
|
|
|
//remove from lhs matches that share a node with a nac match
|
|
|
//TODO if nac is not related to match (no plabels match)
|
|
|
Element final_matches
|
|
|
final_matches = mergeLHSNAC(tf_er_lhs, tf_er_nac)
|
|
|
|
|
|
+ if( read_nr_out(final_matches) == 0 ):
|
|
|
+ return False
|
|
|
+
|
|
|
+
|
|
|
//extract pivots from the matches
|
|
|
- extractPivots(final_matches, pivots, tf_er_transformation, tf_er_model)
|
|
|
+ extractPivots(final_matches, tf_er_transformation, tf_er_model)
|
|
|
|
|
|
//rhs part
|
|
|
|
|
|
@@ -566,7 +575,7 @@ Element function tf_executeFRule(tf_er_transformation: Element,tf_er_rule: Eleme
|
|
|
|
|
|
rhs_rewrite(final_matches ,plabel_to_rhsnode, tf_er_transformation, tf_er_model )
|
|
|
|
|
|
- return pivots
|
|
|
+ return True
|
|
|
|
|
|
Integer function modulo(a:Integer,b:Integer):
|
|
|
return a - integer_division(a,b)*b
|
|
|
@@ -585,13 +594,14 @@ Element function list_select_random(list:Element):
|
|
|
return list_read(list, getRandomNumber(0,read_nr_out(list)))
|
|
|
|
|
|
|
|
|
-Element function tf_executeARule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element, pivots : Element):
|
|
|
+Element function tf_executeARule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element):
|
|
|
|
|
|
//find LHS
|
|
|
- //TODO if no lhs (is this allowed to happen?) // or empty lhs
|
|
|
Element tf_er_lhs
|
|
|
tf_er_lhs = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "lhs"))
|
|
|
- tf_er_lhs = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_lhs)), tf_er_model, pivots)
|
|
|
+ Integer nr_of_lhs_nodes
|
|
|
+ nr_of_lhs_nodes = read_nr_out(tf_er_lhs)
|
|
|
+ tf_er_lhs = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_lhs)), tf_er_model)
|
|
|
Integer nr_of_lhs_matches
|
|
|
nr_of_lhs_matches = list_len(tf_er_lhs)
|
|
|
|
|
|
@@ -605,16 +615,25 @@ Element function tf_executeARule(tf_er_transformation: Element,tf_er_rule: Eleme
|
|
|
tf_er_nac_ = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "nac"))
|
|
|
Element partial_nac_matches
|
|
|
while (read_nr_out(tf_er_nac_) > 0):
|
|
|
- partial_nac_matches = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_nac_)), tf_er_model, pivots)
|
|
|
+ partial_nac_matches = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_nac_)), tf_er_model)
|
|
|
while (read_nr_out(partial_nac_matches)>0):
|
|
|
list_append(tf_er_nac, set_pop(partial_nac_matches))
|
|
|
nr_of_nac_matches = list_len(tf_er_nac)
|
|
|
|
|
|
+ if( nr_of_lhs_nodes == 0):
|
|
|
+ if (nr_of_nac_matches == 0):
|
|
|
+ return True
|
|
|
+ else:
|
|
|
+ return False
|
|
|
+
|
|
|
//remove from lhs matches that share a node with a nac match
|
|
|
//TODO if nac is not related to match (no plabels match)
|
|
|
Element final_matches
|
|
|
final_matches = mergeLHSNAC(tf_er_lhs, tf_er_nac)
|
|
|
|
|
|
+ if( read_nr_out(final_matches) == 0 ):
|
|
|
+ return False
|
|
|
+
|
|
|
//select only one match
|
|
|
Element selected
|
|
|
selected = list_select_random(final_matches)
|
|
|
@@ -623,7 +642,7 @@ Element function tf_executeARule(tf_er_transformation: Element,tf_er_rule: Eleme
|
|
|
|
|
|
|
|
|
//extract pivots from the matches
|
|
|
- extractPivots(final_matches, pivots, tf_er_transformation, tf_er_model)
|
|
|
+ extractPivots(final_matches, tf_er_transformation, tf_er_model)
|
|
|
|
|
|
//rhs part
|
|
|
|
|
|
@@ -648,9 +667,9 @@ Element function tf_executeARule(tf_er_transformation: Element,tf_er_rule: Eleme
|
|
|
|
|
|
rhs_rewrite(final_matches ,plabel_to_rhsnode, tf_er_transformation, tf_er_model )
|
|
|
|
|
|
- return pivots
|
|
|
+ return True
|
|
|
|
|
|
-Element function executeRuleBlock(transformation_model : Element,hostmodel:Element, ruleblock : Element, pivots:Element):
|
|
|
+Element function executeRuleBlock(transformation_model : Element,hostmodel:Element, ruleblock : Element):
|
|
|
//execute the correct ruletype
|
|
|
//TODO define decent succes_value
|
|
|
String typename
|
|
|
@@ -660,22 +679,21 @@ Element function executeRuleBlock(transformation_model : Element,hostmodel:Eleme
|
|
|
Element Rule
|
|
|
if (typename == "RuleBlockRoot"):
|
|
|
// do nothing
|
|
|
- log("start transformation")
|
|
|
+ log("= startinging transformation")
|
|
|
succes = True
|
|
|
elif (typename == "ARule"):
|
|
|
- log("running arule")
|
|
|
+ log("= running ARule")
|
|
|
Rule = read_edge_dst(set_pop(allOutgoingAssociationInstances(transformation_model, ruleblock, transformation_model["metamodel"]["model"]["getrule"])))
|
|
|
log(getName(transformation_model, Rule))
|
|
|
- pivots = tf_executeARule(transformation_model, Rule, hostmodel, pivots)
|
|
|
- succes = True
|
|
|
+ succes = tf_executeARule(transformation_model, Rule, hostmodel)
|
|
|
elif (typename == "FRule"):
|
|
|
- log("running frule")
|
|
|
+ log("= running FRule")
|
|
|
Rule = read_edge_dst(set_pop(allOutgoingAssociationInstances(transformation_model, ruleblock, transformation_model["metamodel"]["model"]["getrule"])))
|
|
|
log(getName(transformation_model, Rule))
|
|
|
- pivots = tf_executeFRule(transformation_model, Rule, hostmodel, pivots)
|
|
|
- succes = True
|
|
|
+ succes = tf_executeFRule(transformation_model, Rule, hostmodel)
|
|
|
else:
|
|
|
log("RuleType is not supported yet")
|
|
|
+
|
|
|
//Return the next
|
|
|
Element next
|
|
|
if succes:
|
|
|
@@ -683,7 +701,6 @@ Element function executeRuleBlock(transformation_model : Element,hostmodel:Eleme
|
|
|
else:
|
|
|
next = allOutgoingAssociationInstances(transformation_model, ruleblock, transformation_model["metamodel"]["model"]["next_onFailure"])
|
|
|
if (read_nr_out(next) == 0):
|
|
|
- log("No next defined")
|
|
|
next = transformation_model
|
|
|
else:
|
|
|
next = read_edge_dst(set_pop(next))
|
|
|
@@ -696,12 +713,11 @@ Element function tf_transform(tf_tf_transformation: Element, tf_tf_model: Elemen
|
|
|
ruleblock = allInstances(tf_tf_transformation, tf_tf_transformation["metamodel"]["model"]["RuleBlockRoot"])
|
|
|
if(read_nr_out(ruleblock) > 0):
|
|
|
ruleblock = set_pop(ruleblock)
|
|
|
- Element pivots
|
|
|
pivots = create_node()
|
|
|
Boolean continue
|
|
|
continue = True
|
|
|
while (continue):
|
|
|
- ruleblock = executeRuleBlock(tf_tf_transformation,tf_tf_model, ruleblock, pivots)
|
|
|
+ ruleblock = executeRuleBlock(tf_tf_transformation,tf_tf_model, ruleblock)
|
|
|
if(element_eq(ruleblock,tf_tf_transformation)):
|
|
|
log("finished")
|
|
|
continue = False
|
|
|
@@ -993,6 +1009,14 @@ Element function petrinet_transformation(root: Element):
|
|
|
//connect to rule
|
|
|
instantiate_link(my_model, "getrule","", "frule3", "produce_tokens")
|
|
|
|
|
|
+ //create circularity link
|
|
|
+ instantiate_link(my_model, "next_onSucces", "", "frule3", "arule1")
|
|
|
+ //if you cannot consume, still try to produce (for source transitions)
|
|
|
+ instantiate_link(my_model, "next_onFailure", "", "frule2", "frule3")
|
|
|
+ //if you cannot produce, still check for other transitions (it might have consumed already)
|
|
|
+ instantiate_link(my_model, "next_onFailure", "", "frule3", "arule1")
|
|
|
+
|
|
|
+
|
|
|
|
|
|
////////////////////////////
|
|
|
// semantic checks
|
|
|
@@ -1060,9 +1084,6 @@ Element function add_tokens(model:Element, self: Element):
|
|
|
unset_attribute(model, getName(model, place_after), "tokens")
|
|
|
instantiate_attribute(model, getName(model, place_after), "tokens", tokens+weight)
|
|
|
return 0
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
Element function pn_operations():
|
|
|
Element ops
|