Browse Source

Optimized instantiate_* further

Yentl Van Tendeloo 8 years ago
parent
commit
368f59aa35
3 changed files with 15 additions and 26 deletions
  1. 14 22
      bootstrap/modelling.alc
  2. 1 1
      integration/test_powerwindow.py
  3. 0 3
      models/bfs.alc

+ 14 - 22
bootstrap/modelling.alc

@@ -99,8 +99,6 @@ Element function instantiate_model(metamodel : Element):
 	return model!
 
 String function instantiate_node(model : Element, type_name : String, instance_name : String):
-	// Create a node typed by a node from the metamodel
-	// Basically create a node and type it immediately
 	String actual_name
 
 	if (bool_not(dict_in(model["metamodel"]["model"], type_name))):
@@ -108,30 +106,25 @@ String function instantiate_node(model : Element, type_name : String, instance_n
 		log("    for " + 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)
+	Element value
+	value = create_node()
 
+	actual_name = instantiated_name(value, instance_name)
+	dict_add_fast(model["model"], actual_name, value)
+	dict_add_fast(model["type_mapping"], actual_name, type_name)
 	return actual_name!
 
 String function instantiate_value(model : Element, type_name : String, instance_name : String, value : Element):
-	// Create a node typed by a node from the metamodel
-	// Basically create a node and type it immediately
 	String actual_name
 
 	if (bool_not(dict_in(model["metamodel"]["model"], type_name))):
 		log("ERROR: (instantiate_value) no such type in metamodel: " + type_name)
 		log("     for " + 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)
-
+	
+	actual_name = instantiated_name(value, instance_name)
+	dict_add_fast(model["model"], actual_name, value)
+	dict_add_fast(model["type_mapping"], actual_name, type_name)
 	return actual_name!
 
 String function find_attribute_type(model : Element, elem : String, name : String):
@@ -324,9 +317,6 @@ 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 (type == ""):
 		// Have to find the type ourselves, as it isn't defined
 		Element out
@@ -351,10 +341,12 @@ String function instantiate_link(model : Element, type : String, name : String,
 		log("ERROR: (instantiate_link) no such type in metamodel: " + type)
 		log("    for " + name)
 		return ""!
-
-	actual_name = model_add_edge(model, name, source, destination)
 	
-	retype(model, actual_name, type)
+	Element v
+	v = create_edge(model["model"][source], model["model"][destination])
+	actual_name = instantiated_name(v, name)
+	dict_add_fast(model["model"], actual_name, v)
+	dict_add_fast(model["type_mapping"], actual_name, type)
 	return actual_name!
 
 Void function model_delete_element(model : Element, name : String):

+ 1 - 1
integration/test_powerwindow.py

@@ -270,7 +270,7 @@ class TestPowerWindow(unittest.TestCase):
                 "exit",
                 # revise_control
                 "upload",
-                ] + get_model_constructor_2("models/control_model.mvc") + [
+                ] + get_model_constructor_2("models/control_model_wrong.mvc") + [
                 "exit",
                 # revise_query
                 "upload",

+ 0 - 3
models/bfs.alc

@@ -29,9 +29,6 @@ Element function bfs(params : Element, output_mms : Element):
 		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!")