Bläddra i källkod

fixed returning matches to were they belong

tpinna 10 år sedan
förälder
incheckning
9f32073784
1 ändrade filer med 34 tillägg och 30 borttagningar
  1. 34 30
      integration/code/pn_interface.alc

+ 34 - 30
integration/code/pn_interface.alc

@@ -79,15 +79,11 @@ Element function printNode(tf_pn_model: Element, tf_pn_node: Element):
 	
 
 Boolean function node_match(transf_model : Element, transf_elem : Element, host_model : Element, host_elem : Element):
-	log("node match")
 	//NOTE maybe get rid of LHS postfix? maybe not
-	log("0")
 	String type1
 	type1 = getTypeName(transf_model, transf_elem)
-	log("1")
 	String type2
 	type2 = string_join(getTypeName(host_model, host_elem), "_LHS")
-	log("2")
 	log(type1)
 	log(type2)
 	if (type1 != type2):
@@ -95,7 +91,6 @@ Boolean function node_match(transf_model : Element, transf_elem : Element, host_
 	return True
 
 Integer function are_connected(model: Element, el1:Element, el2:Element):
-	log("are connected")
 	String el1_mmt
 	String el2_mmt
 	el1_mmt = getMetaTypeName(model, el1)
@@ -127,7 +122,6 @@ Integer function are_connected(model: Element, el1:Element, el2:Element):
 
 
 Element function new_SearchState(OldSearchState : Element, TransfModel : Element, NewTransfElem: Element, HostModel : Element, NewHostElem : Element):
-	log("new searchstate")
 	//some variables
 	Element nss // new searchstate
 	nss = create_node()
@@ -248,7 +242,6 @@ Element function new_SearchState(OldSearchState : Element, TransfModel : Element
 	return nss
 
 Element function transf_vf2(SearchState: Element, transf_m : Element, host_m : Element):
-	log("transf_vf2")
 	
 	// get the current match from the search-state
 	Element current_match
@@ -258,15 +251,19 @@ Element function transf_vf2(SearchState: Element, transf_m : Element, host_m : E
 	//	--> need to check with assistent
 	
 	//if match is complete: add to matches and return
-	log("1")
 	Integer pattern_size
 	pattern_size = SearchState["pattern_size"]
 	if pattern_size == list_len(current_match):
-		set_add(SearchState["matches"], SearchState["curmatch"])
+		log("match found")
+		Element matches 
+		matches = SearchState["matches"]
+		set_add(matches, SearchState["curmatch"])
+		dict_delete(SearchState, "matches")
+		dict_add(SearchState, "matches", matches)
+		log(cast_i2s(list_len(SearchState["matches"])))
 		return SearchState
 	
 	//feasability checks
-	log("2")
 	if (list_len(SearchState["N_pattern_out"]) > list_len(SearchState["N_host_out"])):
 		return SearchState
 	if (list_len(SearchState["N_pattern_in"]) > list_len(SearchState["N_host_in"])):
@@ -275,7 +272,6 @@ Element function transf_vf2(SearchState: Element, transf_m : Element, host_m : E
 		return SearchState
 	
 	//initialise some variables
-	log("3")
 	Integer index2 //an index used for looping trough host_list
 	Element host_list // the set with host nodes to be considered
 	Element pattern_node // node to be tested from the patterns side
@@ -283,7 +279,6 @@ Element function transf_vf2(SearchState: Element, transf_m : Element, host_m : E
 	Element nss //variable for storing next searchstate
 	
 	//search candidate
-	log("4")
 	if ( list_len(SearchState["N_pattern_out"]) > 0 ):
 		//check for candidates in (N_pattern_out, N_host_out)
 		host_list = SearchState["N_host_out"]
@@ -308,17 +303,17 @@ Element function transf_vf2(SearchState: Element, transf_m : Element, host_m : E
 				transf_vf2(nss, transf_m, host_m)
 	elif ( list_len(SearchState["V_pattern"]) > 0 ):
 		//check for candidates in (V_pattern, V_host))
-		log("5")
 		host_list = SearchState["V_host"]
 		pattern_node = list_read(SearchState["V_pattern"], 0)
 		index2 = 0
-		log("6")
 		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)):
 				nss = new_SearchState(SearchState, transf_m, pattern_node, host_m, host_node)
-				transf_vf2(nss, transf_m, host_m)
+				nss = transf_vf2(nss, transf_m, host_m)
+				dict_delete(SearchState, "matches")
+				dict_add(SearchState, "matches", nss["matches"])
 	else:
 		log("no candidate found")
 	return SearchState
@@ -326,30 +321,23 @@ 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 ):
-	log("tf_matchAll")
 	
 	//find all nodes in the pattern
 	
-	log("0")
 	Element tf_ma_metamodelTransf //transformation metamodel
 	tf_ma_metamodelTransf = tf_ma_transformation["metamodel"]["model"]
-	log("01")
 	Element pre2ram_et // type of the pre2ram edge
 	pre2ram_et = dict_read(tf_ma_metamodelTransf, "pre2ram")
-	log("02")
 	Element tf_ma_pattern_edges //all pre2ram edges
 	tf_ma_pattern_edges = allOutgoingAssociationInstances(tf_ma_transformation, tf_ma_pattern, pre2ram_et)
-	log("03")
 	Element tf_ma_ramified_nodes //dict in the form plabel->node
 	tf_ma_ramified_nodes = create_node()
 	Element tf_ma_ramified_node
-	log("04")
 	while (integer_lt(0, list_len(tf_ma_pattern_edges))):
 		tf_ma_ramified_node = read_edge_dst(set_pop(tf_ma_pattern_edges))
 		list_append(tf_ma_ramified_nodes, tf_ma_ramified_node)
 	
 	//find all nodes in the graph that are not related to attributes: ie a userdefined type 
-	log("1")
 	Element hostmodel_mm //metamodel of hostgraph
 	hostmodel_mm = tf_ma_model["metamodel"]["model"]
 	Element hostmodel_keys //keys of all elements in the model
@@ -364,7 +352,6 @@ Element function tf_matchAll(tf_ma_transformation: Element, tf_ma_pattern : Elem
 	
 	// initialise the start-state
 	
-	log("2")
 	//initialise an start state
 	Element SearchState 
 	SearchState = create_node()
@@ -379,17 +366,28 @@ Element function tf_matchAll(tf_ma_transformation: Element, tf_ma_pattern : Elem
 	dict_add(SearchState, "pattern_size", list_len(tf_ma_ramified_nodes))
 	
 	//call vf2 for the matching
-	log("3")
 	SearchState = transf_vf2(SearchState, tf_ma_transformation, tf_ma_model)
 	
-	return dict_read(SearchState,"matches")
+	return SearchState["matches"]
 
 Element function tf_executeRule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element):
+	
+	//find LHS
+	
+	log("FINDING LHS")
 	Element tf_er_lhs
-	// get the lhs of the rule
 	tf_er_lhs = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "lhs"))
-	// find the matches of the rule
-	tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_lhs)), tf_er_model)
+	tf_er_lhs = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_lhs)), tf_er_model)
+	log(string_join(cast_i2s(list_len(tf_er_lhs)), " matches found"))
+	
+	//find NAC
+	
+	log("FINDING NAC")
+	Element tf_er_nac
+	tf_er_nac = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "nac"))
+	tf_er_nac = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_nac)), tf_er_model)
+	log(string_join(cast_i2s(list_len(tf_er_nac])), " matches found"))
+	
 	return 0
 
 Element function tf_transform(tf_tf_transformation: Element, tf_tf_model: Element):
@@ -407,8 +405,8 @@ Element function tf_transform(tf_tf_transformation: Element, tf_tf_model: Elemen
 Element function test_simple_petrinet1(root:Element):
 	//create a petrinet for testing purposes
 	
-	//	P1	->	T1	->	P2
-	//	1	1		2	0
+	//	P1	->	T1	->	P2 	-> T2
+	//	1	1		2	0	1
 	
 	//////////////////////////////////
 	//initialise an empty petrinet
@@ -430,6 +428,12 @@ Element function test_simple_petrinet1(root:Element):
 	//init link2
 	instantiate_link(my_model, "T2P", "l2", "p1", "t1")
 	instantiate_attribute(my_model, "l2", "weight", 2)
+	//init t2
+	instantiate_node(my_model, "Transition", "t2")
+	//init link3
+	instantiate_link(my_model, "T2P", "l3", "p1", "t1")
+	instantiate_attribute(my_model, "l3", "weight", 1)
+	
 	
 	return my_model