Browse Source

Fixes to code and models

Yentl Van Tendeloo 8 years ago
parent
commit
4c68887a48

+ 0 - 12
bootstrap/object_operations.alc

@@ -221,18 +221,6 @@ String function readAssociationSource(model : Element, name : String):
 String function readAssociationDestination(model : Element, name : String):
 	return reverseKeyLookup(model["model"], read_edge_dst(model["model"][name]))!
 
-String function followAssociation(model : Element, element_name : String, association_name : String):
-	Element assocs
-	String assoc
-	Element result
-
-	assocs = allOutgoingAssociationInstances(model, element_name, association_name)
-	result = create_node()
-	while (0 < list_len(assocs)):
-		set_add(result, readAssociationDestination(model, set_pop(assocs)))
-
-	return result!
-
 Element function allAssociationDestinations(model : Element, name : String, association_type : String):
 	Element tmp
 	Element result

+ 5 - 4
bootstrap/transform.alc

@@ -290,7 +290,7 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 	set_add(mappings, initial_mapping)
 	while (read_nr_out(schedule) > 0):
 		current_element = list_pop(schedule, read_nr_out(schedule) - 1)
-		//log("Binding element with label " + cast_v2s(read_attribute(schedule_model, current_element, "label")))
+		log("Binding element with label " + cast_v2s(read_attribute(schedule_model, current_element, "label")))
 		new_mappings = create_node()
 
 		while (read_nr_out(mappings) > 0):
@@ -304,7 +304,7 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 				set_add(new_mappings, new_map)
 
 		mappings = new_mappings
-		//log("Remaining options: " + cast_v2s(read_nr_out(mappings)))
+		log("Remaining options: " + cast_v2s(read_nr_out(mappings)))
 
 		if (read_nr_out(mappings) == 0):
 			// Stop because we have no more options remaining!
@@ -380,6 +380,7 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 	while (read_nr_out(labels_to_add) > 0):
 		// Add the elements linked to these labels
 		label = list_pop(labels_to_add, read_nr_out(labels_to_add) - 1)
+		log("Instantiate label " + label)
 		if (is_edge(schedule_model["model"][RHS_map[label]])):
 			// Edge
 			src = read_attribute(schedule_model, reverse[cast_id2s(read_edge_src(schedule_model["model"][RHS_map[label]]))], "label")
@@ -487,7 +488,7 @@ Boolean function transform_composite(host_model : Element, schedule_model : Elem
 
 	current = set_pop(allAssociationDestinations(schedule_model, composite, "Initial"))
 	while (is_nominal_instance(schedule_model, current, "Rule")):
-		//log("Executing " + current)
+		log("Executing " + current)
 		// Still a rule that we must execute
 		typename = read_type(schedule_model, current)
 		if (typename == "Atomic"):
@@ -540,7 +541,7 @@ Boolean function transform_forall(host_model : Element, schedule_model : Element
 	else:
 		result = False
 
-	//log("Matches in forall: " + cast_v2s(read_nr_out(mappings)))
+	log("Matches in forall: " + cast_v2s(read_nr_out(mappings)))
 	while (read_nr_out(mappings) > 0):
 		mapping = set_pop(mappings)
 		// TODO check if there are actually no deletions happening in the meantime of other matched elements...

+ 18 - 6
core/core_algorithm.alc

@@ -510,12 +510,13 @@ Element function execute_operation(operation_id : String, input_models : Element
 	Boolean tracability
 
 	// 1) Find merged metamodel
+	log("Find merged")
 
 	exact_type = read_type(core, operation_id)
 
 	if (exact_type == "ModelTransformation"):
 		linktype = "RAMified"
-		ramified_metamodel_id = set_pop(followAssociation(core, operation_id, "instanceOf"))
+		ramified_metamodel_id = set_pop(allAssociationDestinations(core, operation_id, "instanceOf"))
 		trace_links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
 	elif (exact_type == "ManualOperation"):
 		linktype = "operatesOn"
@@ -535,6 +536,7 @@ Element function execute_operation(operation_id : String, input_models : Element
 
 	if (merged_metamodel_id != ""):
 		// 2) Merge source models
+		log("Merge source")
 
 		model_tuples = create_node()
 		while (read_nr_out(input_models) > 0):
@@ -546,6 +548,10 @@ Element function execute_operation(operation_id : String, input_models : Element
 		merged_model = model_join(model_tuples, get_full_model(merged_metamodel_id), read_root())
 
 		// 3) Transform
+		log("Transform")
+		log("Source model: " + pretty_print(merged_model))
+		log("Types of merged: " + set_to_string(dict_keys(merged_model["metamodel"]["model"])))
+		log("operation: " + pretty_print(get_full_model(operation_id)))
 
 		if (exact_type == "ModelTransformation"):
 			result = transform(merged_model, get_full_model(operation_id))
@@ -561,6 +567,7 @@ Element function execute_operation(operation_id : String, input_models : Element
 			log("ERROR")
 
 		// 4) Split in different models depending on type
+		log("Split")
 
 		if (element_neq(tracability_model, read_root())):
 			tracability = True
@@ -578,6 +585,7 @@ Element function execute_operation(operation_id : String, input_models : Element
 			result = model_split(merged_model, model_tuples, tracability)
 
 			if (tracability):
+				log("Trace")
 				Element new_tracability_model
 				new_tracability_model = result["__tracability"]
 				dict_overwrite(tracability_model, "model", new_tracability_model["model"])
@@ -585,6 +593,7 @@ Element function execute_operation(operation_id : String, input_models : Element
 				dict_overwrite(tracability_model, "metamodel", new_tracability_model["metamodel"])
 				dict_delete(result, "__tracability")
 
+			log("Done")
 			return result!
 		else:
 			return read_root()!
@@ -879,7 +888,7 @@ Void function user_function_skip_init(user_id : String):
 
 							// Generate a new rendered model only (no write to original model!)
 							outputs = create_node()
-							type_ID = followAssociation(core, mapper_ID, "transformOutput")
+							type_ID = set_pop(allAssociationDestinations(core, mapper_ID, "transformOutput"))
 							set_add(outputs, read_attribute(core, type_ID, "name"))
 
 							// Rendered model doesn't exist yet, so create first
@@ -897,12 +906,15 @@ Void function user_function_skip_init(user_id : String):
 								tracability_model = get_full_model(get_model_id(tracability_name))
 
 							// Do the operation itself!
+							log("Start transformation!")
 							result = execute_operation(mapper_ID, inputs, outputs, tracability_model)
+							log("Transformation done")
 
 							// Overwrite the previous rendered model; tracability updated in-place
 							model_overwrite(result[read_attribute(core, type_ID, "name")], get_model_id(rendered_name))
 
 							// Also output the resulting model
+							output("Mapping success!")
 							output(pretty_print(rendered_name))
 
 						else:
@@ -1035,9 +1047,9 @@ Void function user_function_skip_init(user_id : String):
 			model_id = get_model_id(input())
 			if (model_id != ""):
 				if (allow_write(user_id, model_id)):
-					if (allow_read(user_id, set_pop(followAssociation(core, model_id, "instanceOf")))):
+					if (allow_read(user_id, set_pop(allAssociationDestinations(core, model_id, "instanceOf")))):
 						output("Waiting for model constructors...")
-						new_model = construct_model_raw(get_full_model(set_pop(followAssociation(core, model_id, "instanceOf"))))
+						new_model = construct_model_raw(get_full_model(set_pop(allAssociationDestinations(core, model_id, "instanceOf"))))
 						model_overwrite(new_model, model_id)
 						output("Model overwrite success!")
 					else:
@@ -1088,7 +1100,7 @@ Void function user_function_skip_init(user_id : String):
 			models = allInstances(core, "Model")
 			while (read_nr_out(models) > 0):
 				m = set_pop(models)
-				output(string_join((string_join("  ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(followAssociation(core, m, "instanceOf")), "name")))
+				output(string_join((string_join("  ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")))
 
 		elif (cmd == "model_list_full"):
 			// List all models with full info
@@ -1444,7 +1456,7 @@ Void function user_function_skip_init(user_id : String):
 			models = allInstances(core, "Transformation")
 			while (read_nr_out(models) > 0):
 				m = set_pop(models)
-				output(string_join(("[" + read_type(core, m)) + "]", string_join((string_join(" ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(followAssociation(core, m, "instanceOf")), "name"))))
+				output(string_join(("[" + read_type(core, m)) + "]", string_join((string_join(" ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name"))))
 
 		elif (cmd == "transformation_list_full"):
 			// List all models with full info

+ 4 - 0
core/mini_modify.alc

@@ -26,8 +26,10 @@ String function pretty_print(model : Element):
 
 		if (bool_or(type == "Class", type == "Association")):
 			result = result + ((("  " + v_m) + " : ") + read_type(model, v_m))
+			result = result + "\n"
 			if (type == "Association"):
 				result = result + ((("    " + reverseKeyLookup(model["model"], read_edge_src(model["model"][v_m]))) + " --> ") + reverseKeyLookup(model["model"], read_edge_dst(model["model"][v_m])))
+				result = result + "\n"
 
 			// Defines attributes
 			attr_list = getInstantiatableAttributes(model, v_m)
@@ -35,6 +37,7 @@ String function pretty_print(model : Element):
 			while (0 < read_nr_out(attr_keys)):
 				attr_key = set_pop(attr_keys)
 				result = result + (((("      " + attr_key) + " : ") + cast_v2s(attr_list[attr_key])))
+				result = result + "\n"
 
 			// Has attributes
 			attr_list = getAttributeList(model, v_m)
@@ -45,6 +48,7 @@ String function pretty_print(model : Element):
 					result = result + (((("      " + cast_v2s(attr_key)) + " : ") + cast_v2s(attr_list[attr_key])) + " = (undefined)")
 				else:
 					result = result + ((((("      " + cast_v2s(attr_key)) + " : ") + cast_v2s(attr_list[attr_key])) + " = ") + cast_v2s(read_attribute(model, v_m, attr_key)))
+				result = result + "\n"
 	return result!
 
 Element function modify(model : Element, write : Boolean):

+ 6 - 2
integration/test_mvc.py

@@ -2005,7 +2005,7 @@ class TestModelverseCore(unittest.TestCase):
                     "__merged_CBD_RAM",
                         "instantiate",
                             "Association",
-                            "Tracability",
+                            "TracabilityLink",
                             "CausalBlockDiagrams/Block",
                             "MM_rendered_graphical/Group",
                         "exit",
@@ -2103,8 +2103,12 @@ class TestModelverseCore(unittest.TestCase):
                     "  CBD_RAM : SimpleClassDiagrams",
                     "  my_CBD : CausalBlockDiagrams",
                     "  render_graphical_CBD : CBD_RAM",
+                    "  __merged_CBD_RAM : SimpleClassDiagrams",
                      ]),
                 "Ready for command...",
                 # model_render
-                "",
+                "Model to render?",
+                "Mapper to use?",
+                "Mapping success",
+                None,
             ]))

+ 0 - 1
interface/HUTN/includes/object_operations.alh

@@ -10,7 +10,6 @@ Element function reverseKeyLookupMulti(a: Element, b: Element)
 String function print_dict(dict : Element)
 String function readAssociationSource(model : Element, name : String)
 String function readAssociationDestination(model : Element, name : String)
-String function followAssociation(model : Element, element_name : String, association_name : String)
 Element function allAssociationDestinations(model : Element, name : String, association_type : String)
 Element function allAssociationOrigins(model : Element, name : String, association_type : String)
 Element function allowedAssociationsBetween(model : Element, src : String, dst : String)

+ 23 - 9
models/CBD_mapper.mvc

@@ -76,7 +76,7 @@ A B {
                         String function value(model : Element, name : String, mapping : Element):
                             return "black"!
                         $
-                    value_content = $
+                    value_text = $
                         String function value(model : Element, name : String, mapping : Element):
                             String type
                             type = read_type(model, name)
@@ -98,10 +98,16 @@ A B {
                                 return "PROBE"!
                         $
                 }
-                Post_MM_rendered_graphical/contains (post_block_1, post_block2) {}
-                Post_MM_rendered_graphical/contains (post_block_1, post_block3) {}
+                Post_MM_rendered_graphical/contains (post_block_1, post_block_2) {
+                    label = "4"
+                }
+                Post_MM_rendered_graphical/contains (post_block_1, post_block_3) {
+                    label = "5"
+                }
 
-                Post_Tracability (post_block_0, post_block_1) {}
+                Post_TracabilityLink (post_block_0, post_block_1) {
+                    label = "6"
+                }
             }
         }
 
@@ -127,8 +133,12 @@ A B {
                     label = "4"
                 }
 
-                Pre_Tracability (pre_conn_0, pre_conn_3) {}
-                Pre_Tracability (pre_conn_0, pre_conn_4) {}
+                Pre_TracabilityLink (pre_conn_0, pre_conn_3) {
+                    label = "5"
+                }
+                Pre_TracabilityLink (pre_conn_0, pre_conn_4) {
+                    label = "6"
+                }
             }
             RHS {
                 Post_CausalBlockDiagrams/Block post_conn_0 {
@@ -151,11 +161,15 @@ A B {
                     label = "4"
                 }
 
-                Post_Tracability (post_conn_0, post_conn_3) {}
-                Post_Tracability (post_conn_0, post_conn_4) {}
+                Post_TracabilityLink (post_conn_0, post_conn_3) {
+                    label = "5"
+                }
+                Post_TracabilityLink (post_conn_0, post_conn_4) {
+                    label = "6"
+                }
 
                 Post_MM_rendered_graphical/Line {
-                    label = "5"
+                    label = "7"
                     value_x = $
                         Integer function value(model : Element, name : String, mapping : Element):
                             return read_attribute(model, mapping["3"], "x")!