Bladeren bron

Merge branch 'fixed_transform' into testing

Yentl Van Tendeloo 8 jaren geleden
bovenliggende
commit
8a386f8f28
3 gewijzigde bestanden met toevoegingen van 52 en 43 verwijderingen
  1. 2 0
      bootstrap/core_algorithm.alc
  2. 46 43
      bootstrap/transform.alc
  3. 4 0
      integration/test_powerwindow.py

+ 2 - 0
bootstrap/core_algorithm.alc

@@ -74,6 +74,8 @@ String function get_instanceOf_link(model_id : String, metamodel_id : String):
 		log("WARNING: multiple instanceOf relations were detected for this model; picking one at random!")
 	elif (set_len(all_links) == 0):
 		log("No types found!")
+		log("Source model: " + cast_v2s(read_attribute(core, model_id, "name")))
+		log("Target meta-model: " + cast_v2s(read_attribute(core, metamodel_id, "name")))
 		return read_root()!
 	
 	choice = set_pop(all_links)

+ 46 - 43
bootstrap/transform.alc

@@ -93,13 +93,48 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 	typename = read_type(schedule_model, current_element)
 	original_typename = string_substr(typename, 4, string_len(typename))
 	guaranteed_instance = False
+
+	/////// NEW CODE
+	// Is a node, so find whether or not there are some connections that are already resolved
+	Element ic
+	Element oc
+	String poll
+	String value
+
+	oc = allOutgoingAssociationInstances(schedule_model, current_element, "PreElement")
+	while (bool_and(set_len(oc) > 0, set_len(options) < 2)):
+		poll = set_pop(oc)
+		if (dict_in(map, read_attribute(schedule_model, poll, "label"))):
+			// This incoming link is already defined, so we just have one option: the destination of the link we matched
+			value = readAssociationSource(host_model, map[read_attribute(schedule_model, poll, "label")])
+			if (bool_not(set_in(options, value))):
+				set_add(options, value)
+
+	if (set_len(options) < 2):
+		ic = allIncomingAssociationInstances(schedule_model, current_element, "PreElement")
+		while (bool_and(set_len(ic) > 0, set_len(options) < 2)):
+			poll = set_pop(ic)
+			if (dict_in(map, read_attribute(schedule_model, poll, "label"))):
+				// This incoming link is already defined, so we just have one option: the destination of the link we matched
+				value = readAssociationDestination(host_model, map[read_attribute(schedule_model, poll, "label")])
+				if (bool_not(set_in(options, value))):
+					set_add(options, value)
+		
+	if (set_len(options) == 0):
+		// Is a node and no connections, so we just pick all options
+		options = allInstances(host_model, original_typename)
+		guaranteed_instance = True
+
+	elif (set_len(options) > 1):
+		// Multiple "only" options, which will not work out: no options!
+		return set_create()!
 	
 	if (is_edge(schedule_model["model"][current_element])):
 		Boolean src_in
 		Boolean dst_in
 		// Is an edge, so check for already bound source/target
-		src_label = read_attribute(schedule_model, reverseKeyLookup(schedule_model["model"], read_edge_src(schedule_model["model"][current_element])), "label")
-		dst_label = read_attribute(schedule_model, reverseKeyLookup(schedule_model["model"], read_edge_dst(schedule_model["model"][current_element])), "label")
+		src_label = read_attribute(schedule_model, readAssociationSource(schedule_model, current_element), "label")
+		dst_label = read_attribute(schedule_model, readAssociationDestination(schedule_model, current_element), "label")
 		src_in = set_in(dict_keys(map), src_label)
 		dst_in = set_in(dict_keys(map), dst_label)
 
@@ -107,56 +142,23 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 
 		if (bool_and(src_in, dst_in)):
 			// Source and destination are bound
-			options = allOutgoingAssociationInstances(host_model, map[src_label], original_typename)
+			if (set_len(options) > 0):
+				options = set_overlap(options, allOutgoingAssociationInstances(host_model, map[src_label], original_typename))
 			if (set_len(options) > 0):
 				options = set_overlap(options, allIncomingAssociationInstances(host_model, map[dst_label], original_typename))
 
 		elif (src_in):
 			// Source is bound
-			options = allOutgoingAssociationInstances(host_model, map[src_label], original_typename)
+			options = set_overlap(options, allOutgoingAssociationInstances(host_model, map[src_label], original_typename))
 
 		elif (dst_in):
 			// Destination is bound
-			options = allIncomingAssociationInstances(host_model, map[dst_label], original_typename)
+			options = set_overlap(options, allIncomingAssociationInstances(host_model, map[dst_label], original_typename))
 
 		else:
 			// Neither is bound, so just get all of them
-			options = allInstances(host_model, original_typename)
-	else:
-		// Is a node, so find whether or not there are some connections that are already resolved
-		Element ic
-		Element oc
-		String poll
-		String value
-
-		oc = allOutgoingAssociationInstances(schedule_model, current_element, "PreElement")
-		while (bool_and(set_len(oc) > 0, set_len(options) < 2)):
-			poll = set_pop(oc)
-			if (dict_in(map, read_attribute(schedule_model, poll, "label"))):
-				// This incoming link is already defined, so we just have one option: the destination of the link we matched
-				value = readAssociationSource(host_model, map[read_attribute(schedule_model, poll, "label")])
-				if (bool_not(set_in(options, value))):
-					set_add(options, value)
-
-		if (set_len(options) < 2):
-			ic = allIncomingAssociationInstances(schedule_model, current_element, "PreElement")
-			String value
-			while (bool_and(set_len(ic) > 0, set_len(options) < 2)):
-				poll = set_pop(ic)
-				if (dict_in(map, read_attribute(schedule_model, poll, "label"))):
-					// This incoming link is already defined, so we just have one option: the destination of the link we matched
-					value = readAssociationDestination(host_model, map[read_attribute(schedule_model, poll, "label")])
-					if (bool_not(set_in(options, value))):
-						set_add(options, value)
-			
-		if (set_len(options) == 0):
-			// Is a node and no connections, so we just pick all options
-			options = allInstances(host_model, original_typename)
-			guaranteed_instance = True
-
-		elif (set_len(options) > 1):
-			// Multiple "only" options, which will not work out: no options!
-			return set_create()!
+			options = options
+	////////// END CODE
 
 	// Filter options further
 	Element filtered_options
@@ -200,7 +202,6 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 
 	Element attributes
 	String attribute
-	Element value
 	Element func
 	Boolean result
 	Element attributes_copy
@@ -545,6 +546,8 @@ Boolean function transform_forall(host_model : Element, schedule_model : Element
 	Element mapping
 	Boolean result
 
+	log("Executing rule: " + current)
+
 	mappings = full_match(host_model, schedule_model, current, False)
 
 	if (set_len(mappings) > 0):
@@ -552,7 +555,7 @@ Boolean function transform_forall(host_model : Element, schedule_model : Element
 	else:
 		result = False
 
-	//log("Matches in forall: " + cast_v2s(set_len(mappings)))
+	log("Matches in forall: " + cast_v2s(set_len(mappings)))
 	while (set_len(mappings) > 0):
 		mapping = set_pop(mappings)
 		RHS = set_pop(allAssociationDestinations(schedule_model, current, "RHSLink"))

+ 4 - 0
integration/test_powerwindow.py

@@ -112,6 +112,7 @@ class TestPowerWindow(unittest.TestCase):
         model_add("formalisms/Query", "formalisms/SimpleClassDiagrams", open("models/query.mvc", 'r').read())
         model_add("formalisms/Architecture", "formalisms/SimpleClassDiagrams", open("models/architecture.mvc", 'r').read())
 
+        #model_add("models/pm_powerwindow", "formalisms/ProcessModel", open("models/pm_req_analyse_debug.mvc", 'r').read())
         model_add("models/pm_powerwindow", "formalisms/ProcessModel", open("models/pm_req_analyse.mvc", 'r').read())
 
         transformation_add_MANUAL({"Requirements": "formalisms/Requirements"}, {"Requirements": "formalisms/Requirements"}, "models/revise_req")
@@ -147,6 +148,9 @@ class TestPowerWindow(unittest.TestCase):
         transformation_add_AL({"ReachabilityGraph": "formalisms/ReachabilityGraph"}, {}, "models/bfs", open("models/bfs.alc", 'r').read())
         transformation_add_AL({"EPN_Plant": "formalisms/Encapsulated_PetriNet", "EPN_Control": "formalisms/Encapsulated_PetriNet", "EPN_Environment": "formalisms/Encapsulated_PetriNet"}, {"Encapsulated_PetriNet": "formalisms/Encapsulated_PetriNet"}, "models/merge_EPN", open("models/merge_EPN.alc", 'r').read())
 
+        #transformation_add_AL({"Encapsulated_PetriNet": "Encapsulated_PetriNet"}, {}, "epn_print", open("models/epn_print.alc").read())
+        #transformation_add_AL({"PetriNet": "PetriNet"}, {}, "pn_print", open("models/pn_print.alc").read())
+
         global called
         called = 0