瀏覽代碼

Fixes to tracability model generation

Yentl Van Tendeloo 8 年之前
父節點
當前提交
300e266af6

+ 1 - 2
bootstrap/library.alc

@@ -20,8 +20,7 @@ Element function export_node(model_name : String, model_reference : Element):
 		counter_i = counter_i + 1
 		counter_i = counter_i + 1
 	
 	
 	// current now contains the place where we should add the element
 	// current now contains the place where we should add the element
-	if (bool_not(dict_in(current, splitted[length]))):
-		dict_add(current, splitted[length], model_reference)
+	dict_overwrite(current, splitted[length], model_reference)
 
 
 	return model_reference!
 	return model_reference!
 
 

+ 4 - 4
bootstrap/metamodels.alc

@@ -182,7 +182,7 @@ Element function initialize_bottom(location_bottom : String):
 
 
 	return ltm_bottom!
 	return ltm_bottom!
 
 
-Element function create_metamodels():
+Void function create_metamodels():
 	String location_SCD
 	String location_SCD
 	String location_PN
 	String location_PN
 	String location_bottom
 	String location_bottom
@@ -191,12 +191,12 @@ Element function create_metamodels():
 	location_PN = "models/PetriNets"
 	location_PN = "models/PetriNets"
 	location_bottom = "models/LTM_bottom"
 	location_bottom = "models/LTM_bottom"
 
 
-	if (bool_not(dict_in(dict_read(dict_read(read_root(), "__hierarchy"), "models"), "PetriNets"))):
+	if (element_eq(import_node("models/PetriNets"), read_root())):
 		initialize_PN(location_SCD, location_PN)
 		initialize_PN(location_SCD, location_PN)
-	if (bool_not(dict_in(dict_read(dict_read(read_root(), "__hierarchy"), "models"), "LTM_bottom"))):
+	if (element_eq(import_node("models/LTM_bottom"), read_root())):
 		initialize_bottom(location_bottom)
 		initialize_bottom(location_bottom)
 
 
-	return dict_read(dict_read(read_root(), "__hierarchy"), "models")!
+	return!
 
 
 Void function initialize_AL(scd_location : String, export_location : String):
 Void function initialize_AL(scd_location : String, export_location : String):
 	// TODO this should be written in a file-based model and not created like this in the bootstrap
 	// TODO this should be written in a file-based model and not created like this in the bootstrap

+ 42 - 6
bootstrap/model_management.alc

@@ -161,6 +161,7 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 	while (read_nr_out(models) > 0):
 	while (read_nr_out(models) > 0):
 		tagged_model = set_pop(models)
 		tagged_model = set_pop(models)
 		retyping_key = string_join(list_read(tagged_model, 0), "/")
 		retyping_key = string_join(list_read(tagged_model, 0), "/")
+		log("Retyping key: " + retyping_key)
 		model = list_read(tagged_model, 1)
 		model = list_read(tagged_model, 1)
 
 
 		// Add all elements from 'model'
 		// Add all elements from 'model'
@@ -196,6 +197,7 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 	// Now link in the tracability model
 	// Now link in the tracability model
 	// Go over all TracabilityLink elements and connect them in the merged model as well
 	// Go over all TracabilityLink elements and connect them in the merged model as well
 
 
+	log("Searching for tracability links to join")
 	if (element_neq(tracability_model, read_root())):
 	if (element_neq(tracability_model, read_root())):
 		Element tracability_links
 		Element tracability_links
 		String tracability_link
 		String tracability_link
@@ -203,17 +205,29 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 		String new_name_dst
 		String new_name_dst
 
 
 		tracability_links = allInstances(tracability_model, "TracabilityLink")
 		tracability_links = allInstances(tracability_model, "TracabilityLink")
+		log("Got tracability links to link: " + cast_v2s(read_nr_out(tracability_links)))
 
 
 		while (read_nr_out(tracability_links) > 0):
 		while (read_nr_out(tracability_links) > 0):
 			tracability_link = set_pop(tracability_links)
 			tracability_link = set_pop(tracability_links)
+			log("Processing link " + cast_e2s(tracability_link))
+			log("In tracability model: " + cast_e2s(tracability_model["model"][tracability_link]))
 
 
 			// Get necessary information from the tracability link
 			// Get necessary information from the tracability link
+			log("Source: " + cast_id2s(read_edge_src(tracability_model["model"][tracability_link])))
+			log("Destination: " + cast_id2s(read_edge_dst(tracability_model["model"][tracability_link])))
+			log("Got elem map: " + set_to_string(dict_keys(elem_map)))
+
 			new_name_src = elem_map[cast_id2s(read_edge_src(tracability_model["model"][tracability_link]))]
 			new_name_src = elem_map[cast_id2s(read_edge_src(tracability_model["model"][tracability_link]))]
 			new_name_dst = elem_map[cast_id2s(read_edge_dst(tracability_model["model"][tracability_link]))]
 			new_name_dst = elem_map[cast_id2s(read_edge_dst(tracability_model["model"][tracability_link]))]
 			type = read_attribute(tracability_model, tracability_link, "type")
 			type = read_attribute(tracability_model, tracability_link, "type")
 
 
+			log("Link element from " + new_name_src)
+			log("Link element fo   " + new_name_dst)
+			log("Of type: " + type)
+
 			// Connect the two with the info we have
 			// Connect the two with the info we have
 			new_name = instantiate_link(new_model, type, "", new_name_src, new_name_dst)
 			new_name = instantiate_link(new_model, type, "", new_name_src, new_name_dst)
+			log("New name of link: " + new_name)
 
 
 			if (new_name == ""):
 			if (new_name == ""):
 				log("ERROR: could not create a tracability link; ignoring")
 				log("ERROR: could not create a tracability link; ignoring")
@@ -245,6 +259,8 @@ Element function model_split(merged_model : Element, models : Element, tracabili
 	String source
 	String source
 	String target
 	String target
 	String link
 	String link
+	String src_name
+	String dst_name
 
 
 	result = create_node()
 	result = create_node()
 	tracability_model = instantiate_model(import_node("models/Tracability"))
 	tracability_model = instantiate_model(import_node("models/Tracability"))
@@ -272,16 +288,35 @@ Element function model_split(merged_model : Element, models : Element, tracabili
 				// Got a tracability link!
 				// Got a tracability link!
 				// Is always an edge (for now?)
 				// Is always an edge (for now?)
 				// Find out source and target and hope that they are already present
 				// Find out source and target and hope that they are already present
-
+				log("Create tracability link in model!")
 				src = reverse[cast_id2s(read_edge_src(elem))]
 				src = reverse[cast_id2s(read_edge_src(elem))]
 				dst = reverse[cast_id2s(read_edge_dst(elem))]
 				dst = reverse[cast_id2s(read_edge_dst(elem))]
 
 
-				// All present, so create the link between them
-				source = reuse_element(tracability_model, "Reference", "", read_edge_src(elem))
-				target = reuse_element(tracability_model, "Reference", "", read_edge_dst(elem))
+				src_name = list_read(string_split(read_type(merged_model, src), "/"), 0)
+				dst_name = list_read(string_split(read_type(merged_model, dst), "/"), 0)
+
+				log("Source model name: " + cast_v2s(src_name))
+				log("Destination model name: " + cast_v2s(dst_name))
+				log("Result: " + dict_to_string(result))
+
+				// Check if we actually keep both models around, as otherwise it is useless anyway
+				if (bool_and(dict_in(result, src_name), dict_in(result, dst_name))):
+					if (bool_and(dict_in(mapping, src), dict_in(mapping, dst))):
+						// All present, so create the link between them
+						Element src_model
+						Element dst_model
+
+						src_model = result[src_name]
+						dst_model = result[dst_name]
 
 
-				link = instantiate_link(tracability_model, "TracabilityLink", "", source, target)
-				instantiate_attribute(tracability_model, link, "type", type)
+						source = reuse_element(tracability_model, "Reference", "", src_model["model"][mapping[src]])
+						target = reuse_element(tracability_model, "Reference", "", dst_model["model"][mapping[dst]])
+
+						link = instantiate_link(tracability_model, "TracabilityLink", "", source, target)
+						instantiate_attribute(tracability_model, link, "type", type)
+					else:
+						// Not yet available!
+						set_add(second_keys, key)
 		else:
 		else:
 			retyping_key = splitted[0]
 			retyping_key = splitted[0]
 
 
@@ -320,5 +355,6 @@ Element function model_split(merged_model : Element, models : Element, tracabili
 	// Finally, we also add tracability information as a separate model
 	// Finally, we also add tracability information as a separate model
 	if (tracability):
 	if (tracability):
 		dict_add_fast(result, "__tracability", tracability_model)
 		dict_add_fast(result, "__tracability", tracability_model)
+		log("Tracability model created with # links = " + cast_v2s(read_nr_out(tracability_model["model"])))
 
 
 	return result!
 	return result!

+ 2 - 1
bootstrap/modelling.alc

@@ -107,8 +107,9 @@ String function reuse_element(model : Element, type_name : String, instance_name
 		return ""!
 		return ""!
 
 
 	actual_name = instantiated_name(element, instance_name)
 	actual_name = instantiated_name(element, instance_name)
-	dict_add_fast(model["model"], actual_name, element)
+	dict_add(model["model"], actual_name, element)
 	dict_add_fast(model["type_mapping"], actual_name, type_name)
 	dict_add_fast(model["type_mapping"], actual_name, type_name)
+
 	return actual_name!
 	return actual_name!
 
 
 String function instantiate_node(model : Element, type_name : String, instance_name : String):
 String function instantiate_node(model : Element, type_name : String, instance_name : String):

+ 23 - 3
core/core_algorithm.alc

@@ -589,7 +589,7 @@ Element function execute_operation(operation_id : String, input_models : Element
 			metamodel_name = read_attribute(core, set_pop(allAssociationDestinations(core, model_ID, "instanceOf")), "name")
 			metamodel_name = read_attribute(core, set_pop(allAssociationDestinations(core, model_ID, "instanceOf")), "name")
 			set_add(model_tuples, create_tuple(metamodel_name, input_model))
 			set_add(model_tuples, create_tuple(metamodel_name, input_model))
 
 
-		merged_model = model_join(model_tuples, get_full_model(merged_metamodel_id), read_root())
+		merged_model = model_join(model_tuples, get_full_model(merged_metamodel_id), tracability_model)
 
 
 		// 3) Transform
 		// 3) Transform
 
 
@@ -934,6 +934,8 @@ Void function user_function_skip_init(user_id : String):
 			Element rendered_model
 			Element rendered_model
 			Element tracability_model
 			Element tracability_model
 			Element result
 			Element result
+			Element out_links
+			Element in_links
 
 
 			output("Model to render?")
 			output("Model to render?")
 			model_name = input()
 			model_name = input()
@@ -959,11 +961,21 @@ Void function user_function_skip_init(user_id : String):
 
 
 							// Generate a new rendered model only (no write to original model!)
 							// Generate a new rendered model only (no write to original model!)
 							outputs = create_node()
 							outputs = create_node()
-							type_ID = set_pop(allAssociationDestinations(core, mapper_ID, "transformOutput"))
+							out_links = allAssociationDestinations(core, mapper_ID, "transformOutput")
+							in_links = allAssociationDestinations(core, mapper_ID, "transformInput")
+							while(read_nr_out(out_links) > 0):
+								type_ID = set_pop(out_links)
+								if (bool_not(set_in(in_links, type_ID))):
+									// It is not the AS model, but another one (the MM_rendered)
+									break!
+
+							// Add the model itself as output as well, as otherwise tracability links get messed up!
+							set_add(outputs, read_attribute(core, set_pop(allAssociationDestinations(core, get_model_id(model_name), "instanceOf")), "name"))
 							set_add(outputs, read_attribute(core, type_ID, "name"))
 							set_add(outputs, read_attribute(core, type_ID, "name"))
 
 
 							// Rendered model doesn't exist yet, so create first
 							// Rendered model doesn't exist yet, so create first
 							if (get_model_id(rendered_name) == ""):
 							if (get_model_id(rendered_name) == ""):
+								log("No tracability model yet: create one!")
 								// Rendered model doesn't exist yet, so create first!
 								// Rendered model doesn't exist yet, so create first!
 								rendered_model = instantiate_model(get_full_model(type_ID))
 								rendered_model = instantiate_model(get_full_model(type_ID))
 								model_create(rendered_model, rendered_name, user_id, type_ID, "Model")
 								model_create(rendered_model, rendered_name, user_id, type_ID, "Model")
@@ -974,14 +986,22 @@ Void function user_function_skip_init(user_id : String):
 
 
 							else:
 							else:
 								// Read out tracability model
 								// Read out tracability model
+								log("Reading tracability info")
 								tracability_model = get_full_model(get_model_id(tracability_name))
 								tracability_model = get_full_model(get_model_id(tracability_name))
+								log("Got model of size: " + cast_v2s(read_nr_out(tracability_model["model"])))
 
 
 							// Do the operation itself!
 							// Do the operation itself!
+							log("Rendering with tracability model of size: " + cast_v2s(read_nr_out(tracability_model["model"])))
 							result = execute_operation(mapper_ID, inputs, outputs, tracability_model)
 							result = execute_operation(mapper_ID, inputs, outputs, tracability_model)
+							log("Tracability model updated to size: " + cast_v2s(read_nr_out(tracability_model["model"])))
 
 
-							// Overwrite the previous rendered model; tracability updated in-place
+							// Overwrite the previous rendered model
 							model_overwrite(result[read_attribute(core, type_ID, "name")], get_model_id(rendered_name))
 							model_overwrite(result[read_attribute(core, type_ID, "name")], get_model_id(rendered_name))
 
 
+							// Tracability updated in-place
+							model_overwrite(tracability_model, get_model_id(tracability_name))
+							tracability_model = get_full_model(get_model_id(tracability_name))
+
 							// Also output the resulting model
 							// Also output the resulting model
 							output("Mapping success")
 							output("Mapping success")
 							output(JSON_print(get_full_model(get_model_id(rendered_name))))
 							output(JSON_print(get_full_model(get_model_id(rendered_name))))

+ 1 - 1
interface/HUTN/includes/metamodels.alh

@@ -1,4 +1,4 @@
-Element function create_metamodels()
+Void function create_metamodels()
 Element function initialize_SCD(location : String)
 Element function initialize_SCD(location : String)
 Element function initialize_PN(location_SCD : String, location_PN : String)
 Element function initialize_PN(location_SCD : String, location_PN : String)
 Element function initialize_bottom(location : String)
 Element function initialize_bottom(location : String)

+ 4 - 0
interface/graphical/main.py

@@ -217,6 +217,10 @@ class Window(object):
                 as_ID = findASID(element["id"])
                 as_ID = findASID(element["id"])
                 cs_ID = element["id"]
                 cs_ID = element["id"]
                 group_ID = findGroup(element["id"])
                 group_ID = findGroup(element["id"])
+            elif t in ["Group", "contains", "renders"]:
+                continue
+            else:
+                raise Exception(str(element))
 
 
             if t == "Rectangle":
             if t == "Rectangle":
                 fillColour = element["fillColour"]
                 fillColour = element["fillColour"]

+ 1 - 0
interface/graphical/upload_mappers.py

@@ -58,6 +58,7 @@ commands = [ "root", "root", "root",
                     "CausalBlockDiagrams",
                     "CausalBlockDiagrams",
                     "MM_rendered_graphical",
                     "MM_rendered_graphical",
                     "",
                     "",
+                    "CausalBlockDiagrams",
                     "MM_rendered_graphical",
                     "MM_rendered_graphical",
                     "",
                     "",
                     "render_graphical_CBD",
                     "render_graphical_CBD",

+ 1 - 1
interface/plot/test/wrapper.py

@@ -83,4 +83,4 @@ class Test(unittest.TestCase):
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
     #import sys;sys.argv = ['', 'Test.testName']
     #import sys;sys.argv = ['', 'Test.testName']
-    unittest.main()
+    unittest.main()