|
@@ -406,6 +406,7 @@ Element function tf_executeRule(tf_er_transformation: Element,tf_er_rule: Elemen
|
|
|
nr_of_nac_matches = list_len(tf_er_nac)
|
|
nr_of_nac_matches = list_len(tf_er_nac)
|
|
|
|
|
|
|
|
//remove from lhs matches that share a node with a nac match
|
|
//remove from lhs matches that share a node with a nac match
|
|
|
|
|
+ //TODO if nac is not related to match
|
|
|
Element final_matches
|
|
Element final_matches
|
|
|
final_matches = create_node()
|
|
final_matches = create_node()
|
|
|
Element lhs_match
|
|
Element lhs_match
|
|
@@ -456,8 +457,104 @@ Element function tf_executeRule(tf_er_transformation: Element,tf_er_rule: Elemen
|
|
|
dict_add(pivots, pivotOutName, create_node())
|
|
dict_add(pivots, pivotOutName, create_node())
|
|
|
set_add(pivots[pivotOutName], host_match_node)
|
|
set_add(pivots[pivotOutName], host_match_node)
|
|
|
|
|
|
|
|
- //TODO RHS
|
|
|
|
|
-
|
|
|
|
|
|
|
+ //rhs part
|
|
|
|
|
+
|
|
|
|
|
+ //create plabel_to_rhsnode
|
|
|
|
|
+ log("a")
|
|
|
|
|
+ Element RHS
|
|
|
|
|
+ RHS = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, tf_er_transformation["metamodel"]["model"]["rhs"])
|
|
|
|
|
+ log("a1")
|
|
|
|
|
+ if(read_nr_out(RHS) > 0):
|
|
|
|
|
+ RHS = read_edge_dst(set_pop(RHS))
|
|
|
|
|
+ Element metamodelTransf //transformation metamodel
|
|
|
|
|
+ metamodelTransf = tf_er_transformation["metamodel"]["model"]
|
|
|
|
|
+ Element post2ram // type of the post2ram edge
|
|
|
|
|
+ post2ram = dict_read(metamodelTransf, "post2ram")
|
|
|
|
|
+ log("b")
|
|
|
|
|
+ post2ram = allOutgoingAssociationInstances(tf_er_transformation, RHS, post2ram)
|
|
|
|
|
+ Element plabel_to_rhsnode //dict in the form plabel->node
|
|
|
|
|
+ plabel_to_rhsnode = create_node()
|
|
|
|
|
+ Element rhs_node
|
|
|
|
|
+ Integer rhs_plabel
|
|
|
|
|
+ log("c")
|
|
|
|
|
+ while (integer_lt(0, list_len(post2ram))):
|
|
|
|
|
+ rhs_node = read_edge_dst(set_pop(post2ram))
|
|
|
|
|
+ rhs_plabel = read_attribute(tf_er_transformation, getName(tf_er_transformation, rhs_node), "plabel")
|
|
|
|
|
+ dict_add(plabel_to_rhsnode,rhs_plabel, rhs_node)
|
|
|
|
|
+ //loop over all matches
|
|
|
|
|
+ match_index = 0 //no initialisation, because variable is reused
|
|
|
|
|
+ Element rhs_plabels
|
|
|
|
|
+ Element rhs_action
|
|
|
|
|
+ String new_TypeName
|
|
|
|
|
+ String new_MetaTypeName
|
|
|
|
|
+ Element rhs_to_host //keep this mapping, so that we know wich nodes in the hostmodel new edges connect
|
|
|
|
|
+ Integer source_plabel
|
|
|
|
|
+ Integer destination_plabel
|
|
|
|
|
+ log("d")
|
|
|
|
|
+ while (match_index < read_nr_out(final_matches)):
|
|
|
|
|
+ log("e")
|
|
|
|
|
+ lhs_match = list_read(final_matches, match_index)//reuse lhs_match variable
|
|
|
|
|
+ match_index = match_index +1
|
|
|
|
|
+ //get set of plables
|
|
|
|
|
+ rhs_plabels = dict_keys(plabel_to_rhsnode)
|
|
|
|
|
+ //loop trough every node in the match
|
|
|
|
|
+ lhs_match_keys = dict_keys(lhs_match) // reuse lhs_match_keys variable
|
|
|
|
|
+ rhs_to_host = create_node()
|
|
|
|
|
+ log("f")
|
|
|
|
|
+ while (read_nr_out(lhs_match_keys) > 0):
|
|
|
|
|
+ log("g")
|
|
|
|
|
+ lhs_match_key = set_pop(lhs_match_keys) //reuse this variable
|
|
|
|
|
+ host_match_node = lhs_match[lhs_match_key]["hn"] //reuses the variable
|
|
|
|
|
+ if set_in(rhs_plabels, lhs_match_key): //if node matches plabel with rhs
|
|
|
|
|
+ log("h")
|
|
|
|
|
+ //run function
|
|
|
|
|
+ rhs_action = read_attribute(tf_er_transformation,getName(tf_er_transformation, plabel_to_rhsnode[lhs_match_key]), "function")
|
|
|
|
|
+ rhs_action = tf_er_transformation["actions"][rhs_action]
|
|
|
|
|
+ rhs_action(tf_er_model, host_match_node)
|
|
|
|
|
+ dict_add(rhs_to_host, lhs_match_key, host_match_node)
|
|
|
|
|
+ //remove key from rhs_plabels
|
|
|
|
|
+ set_remove(rhs_plabels, lhs_match_key)
|
|
|
|
|
+ log("i")
|
|
|
|
|
+ else: // if node doesn't match plabel with rhs
|
|
|
|
|
+ log("j")
|
|
|
|
|
+ model_delete_element(tf_er_model, getName(tf_er_model, host_match_node))
|
|
|
|
|
+ log("k")
|
|
|
|
|
+ log("l")
|
|
|
|
|
+ //for each remaining rhs-key (it is not in the match, so should be added)
|
|
|
|
|
+ while (read_nr_out(rhs_plabels) > 0):
|
|
|
|
|
+ log("m")
|
|
|
|
|
+ rhs_plabel = set_pop(rhs_plabels)
|
|
|
|
|
+ //get type and metatype
|
|
|
|
|
+ new_TypeName = string_substr(getTypeName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), 0,-4)
|
|
|
|
|
+ new_MetaTypeName = getMetaTypeName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel])
|
|
|
|
|
+ //if it is a node, than we can simply add it
|
|
|
|
|
+ if (new_MetaTypeName == "Class"):
|
|
|
|
|
+ log("n")
|
|
|
|
|
+ host_match_node = instantiate_node(tf_er_model, new_TypeName, "")
|
|
|
|
|
+ //run the function
|
|
|
|
|
+ rhs_action = read_attribute(tf_er_transformation,getName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), "function")
|
|
|
|
|
+ rhs_action = tf_er_transformation["actions"][rhs_action]
|
|
|
|
|
+ rhs_action(tf_er_model, tf_er_model["model"][host_match_node])
|
|
|
|
|
+ log("o")
|
|
|
|
|
+ elif (new_MetaTypeName == "l5"):
|
|
|
|
|
+ log("p")
|
|
|
|
|
+ //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
|
|
|
|
|
+ source_plabel = read_attribute(tf_er_transformation, getName(tf_er_transformation, read_edge_src(plabel_to_rhsnode[rhs_plabel]) ) , "plabel")
|
|
|
|
|
+ destination_plabel = read_attribute(tf_er_transformation, getName(tf_er_transformation, read_edge_dst(plabel_to_rhsnode[rhs_plabel]) ) , "plabel")
|
|
|
|
|
+ if(bool_and(dict_in(rhs_to_host, source_plabel), dict_in(rhs_to_host, destination_plabel))):
|
|
|
|
|
+ log("q")
|
|
|
|
|
+ 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])))
|
|
|
|
|
+ //run function
|
|
|
|
|
+ rhs_action = read_attribute(tf_er_transformation,getName(tf_er_transformation, plabel_to_rhsnode[rhs_plabel]), "function")
|
|
|
|
|
+ rhs_action = tf_er_transformation["actions"][rhs_action]
|
|
|
|
|
+ rhs_action(tf_er_model, tf_er_model["model"][host_match_node])
|
|
|
|
|
+ log("r")
|
|
|
|
|
+ else:
|
|
|
|
|
+ log("s")
|
|
|
|
|
+ set_add(rhs_plabels, rhs_plabel)
|
|
|
|
|
+ log("t")
|
|
|
|
|
+ else:
|
|
|
|
|
+ log("unsupported metatype in rhs")
|
|
|
return 0
|
|
return 0
|
|
|
|
|
|
|
|
Element function tf_transform(tf_tf_transformation: Element, tf_tf_model: Element):
|
|
Element function tf_transform(tf_tf_transformation: Element, tf_tf_model: Element):
|
|
@@ -472,6 +569,8 @@ Element function tf_transform(tf_tf_transformation: Element, tf_tf_model: Elemen
|
|
|
while (integer_lt(0, read_nr_out(tf_tf_rules))):
|
|
while (integer_lt(0, read_nr_out(tf_tf_rules))):
|
|
|
tf_tf_rule = set_pop(tf_tf_rules)
|
|
tf_tf_rule = set_pop(tf_tf_rules)
|
|
|
//tf_printNode(tf_tf_transformation, tf_tf_rule)
|
|
//tf_printNode(tf_tf_transformation, tf_tf_rule)
|
|
|
|
|
+ log("= EXECUTING RULE")
|
|
|
|
|
+ log(getName(tf_tf_transformation, tf_tf_rule))
|
|
|
tf_executeRule(tf_tf_transformation, tf_tf_rule, tf_tf_model, pivots)
|
|
tf_executeRule(tf_tf_transformation, tf_tf_rule, tf_tf_model, pivots)
|
|
|
return 0
|
|
return 0
|
|
|
|
|
|
|
@@ -584,11 +683,95 @@ Element function petrinet_transformation(root: Element):
|
|
|
//connect to rule
|
|
//connect to rule
|
|
|
instantiate_link(my_model, "pre2ram", "", "nac_precondition", "nac_p2tlhs_before")
|
|
instantiate_link(my_model, "pre2ram", "", "nac_precondition", "nac_p2tlhs_before")
|
|
|
|
|
|
|
|
|
|
+ ////////////////////////////
|
|
|
|
|
+ // rule: consume tokens
|
|
|
|
|
+
|
|
|
|
|
+ //rule: consume_tokens
|
|
|
|
|
+ instantiate_node(my_model, "Rule", "consume_tokens")
|
|
|
|
|
+ instantiate_attribute(my_model, "consume_tokens", "name", "consume_tokens")
|
|
|
|
|
+ instantiate_attribute(my_model, "consume_tokens", "precedence", 2)
|
|
|
|
|
+ //connect to transformation
|
|
|
|
|
+ instantiate_link(my_model, "transformation_to_rule", "", "PetrinetFire", "consume_tokens")
|
|
|
|
|
+
|
|
|
|
|
+ //precondition: lhs_precondition
|
|
|
|
|
+ instantiate_node(my_model, "Precondition","ct_lhs_precondition")
|
|
|
|
|
+ //connect to rule
|
|
|
|
|
+ instantiate_link(my_model, "lhs", "", "consume_tokens", "ct_lhs_precondition")
|
|
|
|
|
+
|
|
|
|
|
+ //Transition_LHS: ct_lhs_transition
|
|
|
|
|
+ instantiate_node(my_model, "Transition_LHS","ct_lhs_transition")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_lhs_transition", "plabel", 1)
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_lhs_transition", "function", "always_true")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_lhs_transition", "pivotOut", "")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_lhs_transition", "pivotIn", "enabled")
|
|
|
|
|
+ //connect to rule
|
|
|
|
|
+ instantiate_link(my_model, "pre2ram", "", "ct_lhs_precondition", "ct_lhs_transition")
|
|
|
|
|
+
|
|
|
|
|
+ //Place_LHS: ct_lhs_place
|
|
|
|
|
+ instantiate_node(my_model, "Place_LHS","ct_lhs_place")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_lhs_place", "plabel", 2)
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_lhs_place", "function", "always_true")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_lhs_place", "pivotOut", "")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_lhs_place", "pivotIn", "enabled")
|
|
|
|
|
+ //connect to rule
|
|
|
|
|
+ instantiate_link(my_model, "pre2ram", "", "ct_lhs_precondition", "ct_lhs_place")
|
|
|
|
|
+
|
|
|
|
|
+ //P2T_LHS: ct_lhs_link
|
|
|
|
|
+ instantiate_link(my_model, "P2T_LHS", "ct_lhs_link", "ct_lhs_place", "ct_lhs_transition")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_lhs_link", "plabel", 3)
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_lhs_link", "function", "always_true")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_lhs_link", "pivotOut", "")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_lhs_link", "pivotIn", "")
|
|
|
|
|
+ //connect to rule
|
|
|
|
|
+ instantiate_link(my_model, "pre2ram", "", "ct_lhs_precondition", "nac_p2tlhs_before")
|
|
|
|
|
+
|
|
|
|
|
+ //precondition: rhs_postcondition
|
|
|
|
|
+ instantiate_node(my_model, "Postcondition","ct_rhs_postcondition")
|
|
|
|
|
+ //connect to rule
|
|
|
|
|
+ instantiate_link(my_model, "rhs", "", "consume_tokens", "ct_rhs_postcondition")
|
|
|
|
|
+
|
|
|
|
|
+ //Transition_RHS: ct_rhs_transition
|
|
|
|
|
+ instantiate_node(my_model, "Transition_RHS","ct_rhs_transition")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_rhs_transition", "plabel", 1)
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_rhs_transition", "function", "do_nothing")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_rhs_transition", "pivotOut", "")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_rhs_transition", "pivotIn", "")
|
|
|
|
|
+ //connect to rule
|
|
|
|
|
+ instantiate_link(my_model, "post2ram", "", "ct_lhs_postcondition", "ct_lhs_transition")
|
|
|
|
|
+
|
|
|
|
|
+ //Place_RHS: ct_rhs_place
|
|
|
|
|
+ instantiate_node(my_model, "Place_RHS","ct_rhs_place")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_rhs_place", "plabel", 2)
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_rhs_place", "function", "do_nothing")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_rhs_place", "pivotOut", "")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_rhs_place", "pivotIn", "")
|
|
|
|
|
+ //connect to rule
|
|
|
|
|
+ instantiate_link(my_model, "post2ram", "", "ct_rhs_postcondition", "ct_rhs_place")
|
|
|
|
|
+
|
|
|
|
|
+ //P2T_RHS: ct_rhs_link
|
|
|
|
|
+ instantiate_link(my_model, "P2T_RHS", "ct_rhs_link", "ct_rhs_place", "ct_rhs_transition")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_rhs_link", "plabel", 3)
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_rhs_link", "function", "remove_tokens")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_rhs_link", "pivotOut", "")
|
|
|
|
|
+ instantiate_attribute(my_model, "ct_rhs_link", "pivotIn", "")
|
|
|
|
|
+ //connect to rule
|
|
|
|
|
+ instantiate_link(my_model, "post2ram", "", "ct_rhs_postcondition", "ct_rhs_link")
|
|
|
|
|
+
|
|
|
|
|
+ ////////////////////////////
|
|
|
|
|
+ // semantic checks
|
|
|
|
|
+
|
|
|
Element semantic_checks
|
|
Element semantic_checks
|
|
|
semantic_checks = create_node()
|
|
semantic_checks = create_node()
|
|
|
dict_add(semantic_checks, "always_true", always_true)
|
|
dict_add(semantic_checks, "always_true", always_true)
|
|
|
dict_add(semantic_checks, "is_not_consumable", is_not_consumable)
|
|
dict_add(semantic_checks, "is_not_consumable", is_not_consumable)
|
|
|
dict_add(my_model, "semantic_checks", semantic_checks)
|
|
dict_add(my_model, "semantic_checks", semantic_checks)
|
|
|
|
|
+
|
|
|
|
|
+ Element actions
|
|
|
|
|
+ actions = create_node()
|
|
|
|
|
+ dict_add(actions, "do_nothing", do_nothing)
|
|
|
|
|
+ dict_add(actions, "remove_tokens", remove_tokens)
|
|
|
|
|
+ dict_add(my_model, "actions", actions)
|
|
|
|
|
+
|
|
|
|
|
|
|
|
return my_model
|
|
return my_model
|
|
|
|
|
|
|
@@ -606,6 +789,26 @@ Boolean function is_not_consumable(model : Element, matched_node : Element):
|
|
|
|
|
|
|
|
Boolean function always_true(model : Element, self : Element):
|
|
Boolean function always_true(model : Element, self : Element):
|
|
|
return True
|
|
return True
|
|
|
|
|
+
|
|
|
|
|
+Element function do_nothing(model: Element, self : Element):
|
|
|
|
|
+ return 0
|
|
|
|
|
+
|
|
|
|
|
+Element function remove_tokens(model:Element, self: Element):
|
|
|
|
|
+ //get place before
|
|
|
|
|
+ Element place_before
|
|
|
|
|
+ place_before = read_edge_src(self)
|
|
|
|
|
+ //get tokens from place
|
|
|
|
|
+ Integer tokens
|
|
|
|
|
+ tokens = read_attribute(model, getName(model, place_before), "tokens")
|
|
|
|
|
+ //get weight from matched_node
|
|
|
|
|
+ Integer weight
|
|
|
|
|
+ weight = read_attribute(model, getName(model, self), "weight")
|
|
|
|
|
+ //rewrite tokens
|
|
|
|
|
+ unset_attribute(model, getName(model, place_before), "tokens")
|
|
|
|
|
+ instantiate_attribute(model, getName(model, place_before), "tokens", tokens-weight)
|
|
|
|
|
+ return 0
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
Element function pn_operations():
|
|
Element function pn_operations():
|