Sfoglia il codice sorgente

started vf2 by implementing searchstate object

tpinna 10 anni fa
parent
commit
25104f8fe2
1 ha cambiato i file con 54 aggiunte e 12 eliminazioni
  1. 54 12
      integration/code/pn_interface.alc

+ 54 - 12
integration/code/pn_interface.alc

@@ -11,10 +11,8 @@ include "modelling.alh"
 Element function find_attribute_type_s(model : Element, elem : String, name : String):
 	Element mm_elem
 	Element direct_type
-
 	direct_type = dict_read_node(model["type_mapping"], model["model"][elem])
 	mm_elem = find_attribute_definer(model["metamodel"], direct_type, name)
-
 	if (element_eq(mm_elem, read_root())):
 		// Couldn't find element, so is not allowed!
 		log("Undefined attribute!")
@@ -22,14 +20,21 @@ Element function find_attribute_type_s(model : Element, elem : String, name : St
 	else:
 		return getName(model["metamodel"], read_edge_dst( dict_read_edge(mm_elem, name)))
 
+
+
 //function to print information about a node (attributes, type and name)
 Element function printNode(tf_pn_model: Element, tf_pn_node: Element):
-	//print header name
+	
+	//print header with name and type
+	
 	String tf_pn_node_name
 	tf_pn_node_name = getName(tf_pn_model, tf_pn_node)
 	log(string_join("name: ",tf_pn_node_name) )
 	log(string_join("type: ", getName(tf_pn_model["metamodel"], dict_read_node(tf_pn_model["type_mapping"], tf_pn_node)) ))
 	//log(getName(tf_pn_model["metamodel"], dict_read_node(tf_pn_model["type_mapping"], tf_pn_node)))
+	
+	//print attributes
+	
 	log("attributes:")
 	//get the list of attributes
 	Element tf_pn_attributelist
@@ -48,21 +53,58 @@ Element function printNode(tf_pn_model: Element, tf_pn_node: Element):
 			log(string_join(tf_pn_attributename, " : "))
 			log(read_attribute(tf_pn_model, tf_pn_node_name, tf_pn_attributename))
 	return 0
+	
+
+Element function tf_recursive_matchAll():
+
 
 // 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 ):
-	Element tf_ma_metamodelTransf
-	tf_ma_metamodelTransf = dict_read(dict_read(tf_ma_transformation, "metamodel"), "model")
-	Element tf_ma_pattern_nodes
-	tf_ma_pattern_nodes = create_node()
-	tf_ma_pattern_nodes = allOutgoingAssociationInstances(tf_ma_transformation, tf_ma_pattern, dict_read(tf_ma_metamodelTransf, "pre2ram"))
-	//check if this works
+	
+	//find all nodes in the pattern
+	
+	Element tf_ma_metamodelTransf //transformation metamodel
+	tf_ma_metamodelTransf = tf_ma_transformation["metamodel"]["model"]
+	Element pre2ram_et // type of the pre2ram edge
+	pre2ram_et = dict_read(tf_ma_metamodelTransf, "pre2ram")
+	Element tf_ma_pattern_edges //all pre2ram edges
+	tf_ma_pattern_edges = allOutgoingAssociationInstances(tf_ma_transformation, tf_ma_pattern, pre2ram_et)
+	Element tf_ma_ramified_nodes //dict in the form plabel->node
 	Element tf_ma_ramified_node
 	while (integer_lt(0, read_nr_out(tf_ma_pattern_nodes))):
 		tf_ma_ramified_node = read_edge_dst(set_pop(tf_ma_pattern_nodes))
-		printNode(tf_ma_transformation, tf_ma_ramified_node)
-		log(read_attribute(tf_ma_transformation, getName(tf_ma_transformation, tf_ma_ramified_node), "plabel"))
-	return 0
+		set_add(tf_ma_ramified_nodes, tf_ma_ramified_node)
+	
+	//find all nodes in the graph
+	//TODO is this necessary (is it not easier to use allinstance to create the initial Vh_Vg pair)?
+	
+	Element hostmodel_mm //metamodel of hostgraph
+	hostmodel_mm = tf_ma_model["metamodel"]["model"]
+	Element hostmodel_keys //keys of all elements in the model
+	hostmodel_keys = dict_keys(tf_ma_model["model"])
+	Element host_nodes //all nodes in the host graph
+	Element host_model_key
+	while (integer_lt(0, read_nr_out(hostmodel_keys))):
+		host_model_key = set_pop(hostmodel_keys)
+		set_add(host_nodes, tf_ma_model["model"][host_model_key])
+	
+	// initialise the start-state
+	
+	//initialise an start state
+	Element SearchState 
+	SearchState = create_node()
+	dict_add(SearchState, "matches", create_node())
+	dict_add(SearchState, "curmatch", create_node())
+	dict_add(SearchState, "N_pattern_out", create_node())
+	dict_add(SearchState, "N_host_out", create_node())
+	dict_add(SearchState, "N_pattern_in", create_node())
+	dict_add(SearchState, "N_host_in", create_node())
+	dict_add(SearchState, "V_pattern", tf_ma_ramified_nodes)
+	dict_add(SearchState, "V_host", host_nodes)
+	
+	//call vf2 for the matching
+	
+	return transf_vf2(SearchState)["matches"]
 
 Element function tf_executeRule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element):
 	Element tf_er_lhs