Browse Source

Slight improvement to the instantiate_* code

Yentl Van Tendeloo 8 years ago
parent
commit
5c127442b9
4 changed files with 86 additions and 14 deletions
  1. 6 6
      bootstrap/modelling.alc
  2. 0 4
      core/core_algorithm.alc
  3. 59 1
      integration/test_powerwindow.py
  4. 21 3
      models/bfs.alc

+ 6 - 6
bootstrap/modelling.alc

@@ -108,8 +108,8 @@ String function instantiate_node(model : Element, type_name : String, instance_n
 		log("    for " + instance_name)
 		return ""!
 
-	if (dict_in(model["model"], instance_name)):
-		return ""!
+	//if (dict_in(model["model"], instance_name)):
+	//	return ""!
 
 	actual_name = model_add_node(model, instance_name)
 	retype(model, actual_name, type_name)
@@ -126,8 +126,8 @@ String function instantiate_value(model : Element, type_name : String, instance_
 		log("     for " + instance_name)
 		return ""!
 
-	if (dict_in(model["model"], instance_name)):
-		return ""!
+	//if (dict_in(model["model"], instance_name)):
+	//	return ""!
 
 	actual_name = model_add_value(model, instance_name, value)
 	retype(model, actual_name, type_name)
@@ -324,8 +324,8 @@ String function instantiate_link(model : Element, type : String, name : String,
 	// Create a typed link between two nodes
 	String actual_name
 
-	if (dict_in(model["model"], name)):
-		return ""!
+	//if (dict_in(model["model"], name)):
+	//	return ""!
 
 	if (type == ""):
 		// Have to find the type ourselves, as it isn't defined

+ 0 - 4
core/core_algorithm.alc

@@ -497,7 +497,6 @@ Boolean function enact_action(pm : Element, element : String, prefix : String, u
 		value = read_attribute(pm, readAssociationDestination(pm, consumes_link), "name")
 		dict_add(inputs, name, prefix + value)
 		dict_add(types, name, read_attribute(pm, readAssociationDestination(pm, consumes_link), "type"))
-		log("Added inputs: " + cast_v2s(prefix + value))
 
 	// Find all outputs and their types (i.e., key)
 	lst = allAssociationDestinations(pm, element, "Produces")
@@ -547,7 +546,6 @@ Boolean function enact_action(pm : Element, element : String, prefix : String, u
 			input_keys = dict_keys(inputs)
 			while (read_nr_out(input_keys) > 0):
 				key = set_pop(input_keys)
-				log("READ model with name " + cast_v2s(inputs[key]))
 				model_join(merged_model, get_full_model(get_model_id(inputs[key])), string_join(types[key], "/"))
 
 			// 3) Transform
@@ -564,8 +562,6 @@ Boolean function enact_action(pm : Element, element : String, prefix : String, u
 				desired_metamodel_id = get_model_id(key)
 				split_off_model = model_split(merged_model, get_full_model(desired_metamodel_id), key + "/")
 
-				log("Wrote model to " + cast_v2s(outputs[key]))
-
 				// Check if the destination model already exists
 				if (get_model_id(outputs[key]) == ""):
 					// New model

+ 59 - 1
integration/test_powerwindow.py

@@ -270,7 +270,7 @@ class TestPowerWindow(unittest.TestCase):
                 "exit",
                 # revise_control
                 "upload",
-                ] + get_model_constructor_2("models/control_model_wrong.mvc") + [
+                ] + get_model_constructor_2("models/control_model.mvc") + [
                 "exit",
                 # revise_query
                 "upload",
@@ -680,6 +680,7 @@ class TestPowerWindow(unittest.TestCase):
                 "upload",
                 ] + get_model_constructor_2("models/requirements_model.mvc") + [
                 "exit",
+                #### First phase!
                 # revise_plant
                 "upload",
                 ] + get_model_constructor_2("models/plant_model.mvc") + [
@@ -700,6 +701,27 @@ class TestPowerWindow(unittest.TestCase):
                 "upload",
                 ] + get_model_constructor_2("models/architecture_model.mvc") + [
                 "exit",
+                #### Second phase!
+                # revise_plant
+                "upload",
+                ] + get_model_constructor_2("models/plant_model.mvc") + [
+                "exit",
+                # revise_environment
+                "upload",
+                ] + get_model_constructor_2("models/environment_model.mvc") + [
+                "exit",
+                # revise_control
+                "upload",
+                ] + get_model_constructor_2("models/control_model.mvc") + [
+                "exit",
+                # revise_query
+                "upload",
+                ] + get_model_constructor_2("models/query_model.mvc") + [
+                "exit",
+                # revise_architecture
+                "upload",
+                ] + get_model_constructor_2("models/architecture_model.mvc") + [
+                "exit",
             ],
             [   # bootup phase
                 "Desired username for admin user?",
@@ -871,6 +893,42 @@ class TestPowerWindow(unittest.TestCase):
                 "Waiting for model constructors...",
                 "Please give your command.",
                 # Computations happen without output
+                # Got an error!
+                # Manual transformation revise_plant
+                "Please perform manual transformation \"revise_plant\"",
+                "Model loaded, ready for commands!",
+                "Use 'help' command for a list of possible commands",
+                "Please give your command.",
+                "Waiting for model constructors...",
+                "Please give your command.",
+                # Manual transformation revise_environment
+                "Please perform manual transformation \"revise_environment\"",
+                "Model loaded, ready for commands!",
+                "Use 'help' command for a list of possible commands",
+                "Please give your command.",
+                "Waiting for model constructors...",
+                "Please give your command.",
+                # Manual transformation revise_control
+                "Please perform manual transformation \"revise_control\"",
+                "Model loaded, ready for commands!",
+                "Use 'help' command for a list of possible commands",
+                "Please give your command.",
+                "Waiting for model constructors...",
+                "Please give your command.",
+                # Manual transformation revise_query
+                "Please perform manual transformation \"revise_query\"",
+                "Model loaded, ready for commands!",
+                "Use 'help' command for a list of possible commands",
+                "Please give your command.",
+                "Waiting for model constructors...",
+                "Please give your command.",
+                # Manual transformation revise_architecture
+                "Please perform manual transformation \"revise_architecture\"",
+                "Model loaded, ready for commands!",
+                "Use 'help' command for a list of possible commands",
+                "Please give your command.",
+                "Waiting for model constructors...",
+                "Please give your command.",
                 # Finished, so we go back to the start
                 "Ready for command...",
             ]))

+ 21 - 3
models/bfs.alc

@@ -12,18 +12,30 @@ Element function bfs(params : Element, output_mms : Element):
 	Element path
 	Element path_copy
 	String option
+	Element visited
+	String dest
+	Integer total_states
 
 	model = params["reachability_graph"]
+	total_states = read_nr_out(allInstances(model, "State"))
 
 	worklist = create_node()
+	visited = create_node()
 	initial = set_pop(allInstances(model, "InitialState"))
 	list_append(worklist, create_tuple(initial, create_node()))
+	set_add(visited, initial)
 
 	while (read_nr_out(worklist) > 0):
 		work_unit = list_pop(worklist, 0)
 		state = work_unit[0]
 		path = work_unit[1]
 		log("Searching for length " + cast_v2s(read_nr_out(path)))
+		log("Visited: " + cast_v2s(read_nr_out(visited)))
+		log("Visit: " + cast_v2s(state))
+
+		if (read_nr_out(visited) == total_states):
+			log("No error path found!")
+			break!
 
 		if (value_eq(read_attribute(model, state, "error"), True)):
 			// Found an error path!
@@ -37,8 +49,14 @@ Element function bfs(params : Element, output_mms : Element):
 
 		while (read_nr_out(options) > 0):
 			option = set_pop(options)
-			path_copy = dict_copy(path)
-			list_append(path_copy, read_attribute(model, option, "name"))
-			list_append(worklist, create_tuple(readAssociationDestination(model, option), path_copy))
+			dest = readAssociationDestination(model, option)
+
+			if (set_in(visited, dest)):
+				continue!
+			else:
+				path_copy = dict_copy(path)
+				list_append(path_copy, read_attribute(model, option, "name"))
+				list_append(worklist, create_tuple(dest, path_copy))
+				set_add(visited, dest)
 
 	return create_node()!