Browse Source

Fixed live modelling for CTCBD models

Yentl Van Tendeloo 5 years ago
parent
commit
d41ae4e8b5

+ 1 - 14
bootstrap/conformance_finding.alc

@@ -91,22 +91,12 @@ Boolean function find_type_mapping(model : Element):
 			return True!
 
 		// Simple allocation: this seems like a dictionary model or so
-		log("Edges: " + cast_string(set_len(edges)))
-		log("Nodes: " + cast_string(set_len(nodes)))
 		if (bool_and(set_len(edges) == 2, set_len(nodes) == 3)):
-			log("Potential dictionary...")
 			String main_edge
 			String small_edge
 			main_edge = set_pop(edges)
 			small_edge = set_pop(edges)
 
-			log("Main edge: " + main_edge)
-			log("Small edge: " + small_edge)
-			log("Main source: " + readAssociationSource(model["metamodel"], main_edge))
-			log("Main destination: " + readAssociationDestination(model["metamodel"], main_edge))
-			log("Small source: " + readAssociationSource(model["metamodel"], small_edge))
-			log("Small destination: " + readAssociationDestination(model["metamodel"], small_edge))
-
 			if (readAssociationSource(model["metamodel"], main_edge) == small_edge):
 				// Switch both
 				log("Switch")
@@ -138,21 +128,18 @@ Boolean function find_type_mapping(model : Element):
 							// Source is main_edge and target is key
 							middle_edge = readAssociationSource(model, elem)
 							retype(model, middle_edge, main_edge)
-							log("Type " + middle_edge + " : " + main_edge)
 							retype(model, readAssociationDestination(model, elem), key)
-							log("Type " + readAssociationDestination(model, elem) + " : " + key)
 
 							// The main_edge goes from root to the value
 							retype(model, readAssociationSource(model, middle_edge), origin)
-							log("Type " + readAssociationSource(model, middle_edge) + " : " + origin)
 							retype(model, readAssociationDestination(model, middle_edge), value)
-							log("Type " + readAssociationDestination(model, middle_edge) + " : " + value)
 
 				return True!
 
 		log("Could not automatically deduce mapping in a trivial way!")
 		log("Model: " + set_to_string(dict_keys(model["model"])))
 		log("TM: " + set_to_string(dict_keys(tm)))
+		log("DIFF: " + set_to_string(set_difference(dict_keys(model["model"]), dict_keys(tm))))
 		return False!
 
 	return True!

+ 1 - 3
bootstrap/transform.alc

@@ -420,6 +420,7 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 			typename = read_type(schedule_model, RHS_map[label])
 			original_typename = string_substr(typename, 5, string_len(typename))
 			new_name = instantiate_node(host_model, original_typename, new_identifier)
+			log("Added element " + new_name + " typed by " + original_typename)
 			dict_add_fast(new_mapping, label, new_name)
 
 	Element attributes
@@ -545,8 +546,6 @@ Boolean function transform_atomic(host_model : Element, schedule_model : Element
 	Element mappings
 	Element mapping
 
-	//log("Executing rule: " + current)
-
 	mappings = full_match(host_model, schedule_model, current, True)
 
 	//log("Executing rule: " + current)
@@ -560,7 +559,6 @@ Boolean function transform_atomic(host_model : Element, schedule_model : Element
 		//log("Rewrite OK")
 		return True!
 	else:
-		log("Rewrite failed")
 		return False!
 
 Boolean function transform_forall(host_model : Element, schedule_model : Element, current : String):

+ 5 - 2
bootstrap/typing.alc

@@ -72,7 +72,10 @@ Void function new_type_mapping(model : Element):
 
 Void function remove_type(model : Element, name : String):
 	Element value
-	value = dict_read(model["type_mapping"]["root"], name)
+	//value = dict_read(model["type_mapping"]["root"], name)
+	value = dict_read_edge(model["type_mapping"]["root"], name)
 	if (element_neq(value, read_root())):
-		delete_element(reverseKeyLookup(model["type_mapping"], value))
+		// TODO why is this a reverseKeyLookup? This means that it will not be removed, as it resolves to a constant...
+		//delete_element(reverseKeyLookup(model["type_mapping"], value))
+		delete_element(value)
 	return !

+ 0 - 1
bootstrap/utils.alc

@@ -32,7 +32,6 @@ String function JSON_print(model : Element):
 			result = result + "{"
 			result = result + "\"__id\": \"" + v_m + "\""
 			result = result + "," + "\"__type\": \"" + read_type(model, v_m) + "\""
-			log("Read type : " + cast_string(read_type(model, v_m)))
 			if (type == "Association"):
 				result = result + ", \"__source\": \"" + reverseKeyLookup(model["model"], read_edge_src(model["model"][v_m])) + "\""
 				result = result + ", \"__target\": \"" + reverseKeyLookup(model["model"], read_edge_dst(model["model"][v_m])) + "\""

+ 1 - 1
examples/live_modelling_CTCBD.py

@@ -19,7 +19,7 @@ transformation_add_MANUAL({"Design": "formalisms/CTCBD/Design_MM"}, {"Design": "
 def trace_D2P(model):
     instantiate(model, "Association", ("Design/Block", "PartialRuntime/Block"), ID="D2P_block")
 
-transformation_add_MT({"Design": "formalisms/CTCBD/Design_MM", "PartialRuntime": "formalisms/DTCBD/PartialRuntime_MM"}, {"PartialRuntime": "formalisms/DTCBD/PartialRuntime_MM"}, "models/CTCBD/toRuntime", open("models/CTCBD/transformations/to_partial_runtime.mvc", 'r').read(), trace_D2P)
+transformation_add_MT({"Design": "formalisms/CTCBD/Design_MM"}, {"PartialRuntime": "formalisms/DTCBD/PartialRuntime_MM"}, "models/CTCBD/toRuntime", open("models/CTCBD/transformations/to_partial_runtime.mvc", 'r').read(), trace_D2P)
 
 def trace_P2F(model):
     instantiate(model, "Association", ("PartialRuntime/Block", "FullRuntime/Block"), ID="P2F_block")

+ 8 - 4
kernel/modelverse_kernel/compiled.py

@@ -315,6 +315,7 @@ def list_pop_final(a, **remainder):
 def instantiate_node(a, b, c, **remainder):
     if "value" not in c:
         c['value'], = yield [("RV", [c['id']])]
+        
     if "id" not in b:
         b['id'], = yield [("CNV", [b['value']])]
 
@@ -415,13 +416,16 @@ def retype(a, b, c, **remainder):
         c['value'], = yield [("RV", [c['id']])]
 
     tm, = yield [("RD", [a["id"], "type_mapping"])]
+    root, = yield [("RD", [tm, "root"])]
 
     # remove_type
-    root, = yield [("RD", [tm, "root"])]
-    val_edge, = yield [("RDE", [root, b["value"]])]
-    if val_edge is not None:
+    val, = yield [("RD", [root, b["value"]])]
+    if val is not None:
         # Key exists, so remove
-        yield [("DE", [val_edge])]
+        if b['value'] == "int0_int1_D2":
+            v, = yield [("RD", [root, b['value']])]
+            v, = yield [("RV", [v])]
+        yield [("DN", [val])]
 
     # Create new type links
     type_elem, instance_elem = yield [("CNV", [c['value']]), ("CNV", [b['value']])]

+ 0 - 3
models/CTCBD/PM_live_modelling.mvc

@@ -77,9 +77,6 @@ Produces (edit, design_model) {
 Consumes (toRuntime, design_model) {
     name = "Design"
 }
-Consumes (toRuntime, partial_runtime_model) {
-    name = "PartialRuntime"
-}
 Consumes (toRuntime, traceability_D2P) {
     name = "__traceability"
 }

+ 0 - 2
models/CTCBD/transformations/to_partial_runtime.mvc

@@ -66,7 +66,6 @@ Composite schedule {
                             String function new_id(model : Element, mapping : Element):
                                 String result
                                 result = cast_string(list_read(string_split(mapping["1"], "/"), 1)) + "_" + cast_string(list_read(string_split(mapping["2"], "/"), 1)) + "_D1"
-                                log("Generate new delayblock with ID " + result)
                                 return result!
                          $
             }
@@ -76,7 +75,6 @@ Composite schedule {
                             String function new_id(model : Element, mapping : Element):
                                 String result
                                 result = cast_string(list_read(string_split(mapping["1"], "/"), 1)) + "_" + cast_string(list_read(string_split(mapping["2"], "/"), 1)) + "_D2"
-                                log("Generate new delayblock with ID " + result)
                                 return result!
                          $
             }

+ 0 - 39
models/DTCBD/transformations/simulate.alc

@@ -8,7 +8,6 @@ include "mini_modify.alh"
 include "utils.alh"
 
 Boolean function main(model : Element):
-	log("Start DTCBD simulation!")
 	String cmd
 	Boolean running
 	Element schedule_init
@@ -19,7 +18,6 @@ Boolean function main(model : Element):
 	String time
 	time = set_pop(allInstances(model, "FullRuntime/Time"))
 	current_time = read_attribute(model, time, "current_time")
-	log("Fetching time now: " + cast_value(current_time))
 
 	schedule_init = create_schedule(model)
 	schedule_run = read_root()
@@ -43,7 +41,6 @@ Boolean function main(model : Element):
 		current_time = step_simulation(model, schedule, current_time, inputs)
 
 	instantiate_attribute(model, time, "current_time", current_time)
-	log("CLOSE")
 	output("CLOSE")
 	return True!
 
@@ -59,7 +56,6 @@ Element function create_schedule(model : Element):
 	successors = set_create()
 	while (set_len(nodes) > 0):
 		element_name = set_pop(nodes)
-		log("Block " + element_name + " : " + read_type(model, element_name))
 
 		if (is_nominal_instance(model, element_name, "FullRuntime/ICBlock")):
 			if (bool_not(is_physical_float(read_attribute(model, element_name, "last_in")))):
@@ -73,19 +69,9 @@ Element function create_schedule(model : Element):
 			String source
 			source = readAssociationSource(model, set_pop(incoming_links))
 			list_append(successors, create_tuple(source, element_name))
-			log("Found edge: " + source + " --> " + element_name)
 
 	Element values
 	values = create_node()
-	//dict_add(values, "model", model)
-	//dict_add(values, "S", create_node())
-	//dict_add(values, "index", 0)
-	//dict_add(values, "indices", create_node())
-	//dict_add(values, "lowlink", create_node())
-	//dict_add(values, "onStack", create_node())
-	//dict_add(values, "successors", successors)
-	//dict_add(values, "predecessors", predecessors)
-	//dict_add(values, "SCC", create_node())
 
 	dict_add(values, "edges", successors)
 	dict_add(values, "nodes", allInstances(model, "FullRuntime/Block"))
@@ -94,39 +80,21 @@ Element function create_schedule(model : Element):
 	dict_add(values, "visited_topSort", set_create())
 	dict_add(values, "unvisited_strongComp", set_create())
 
-	log("Toposort")
-	//nodes = get_topolist(values)
-	//while (list_len(nodes) > 0):
-	//	log("Strong connect")
-	//	strongconnect(list_pop_final(nodes), values)
-
 	dict_overwrite(values, "SCC", strongComp(values))
 
-	//nodes = allInstances(model, "FullRuntime/Block")
-	//while (set_len(nodes) > 0):
-	//	strongconnect(set_pop(nodes), values)
-
-	log("OK")
-
 	return values["SCC"]!
 
 Void function topSort(values : Element):
 	Element nodes_copy
 	String node
 
-	// for node in graph:
-	//     node.visited = False
 	dict_overwrite(values, "visited_topSort", set_create())
 
-	// for node in graph:
-	//     if not node.visited:
-	//          dfsLabelling(node)
 	nodes_copy = set_copy(values["nodes"])
 	while (set_len(nodes_copy) > 0):
 		node = set_pop(nodes_copy)
 		if (bool_not(set_in(values["visited_topSort"], node))):
 			dfsLabelling(values, node)
-	log("Order: " + dict_to_string(values["orderNumber"]))
 
 	return!
 
@@ -238,7 +206,6 @@ Element function strongComp(values : Element):
 
 		component = dfsCollect(values, start_node)
 		list_append(sccs, component)
-		log("Got strong component: " + list_to_string(component))
 
 	return sccs!
 
@@ -329,7 +296,6 @@ Void function strongconnect(v : String, values : Element):
 			list_append(scc, w)
 		// output the current strongly connected component
 		list_insert(values["SCC"], scc, 0)
-		log("Found new SCC: " + list_to_string(scc))
 	return!
 
 Boolean function solve_scc(model : Element, scc : Element):
@@ -423,9 +389,6 @@ Boolean function solve_scc(model : Element, scc : Element):
 
 		i = i + 1
 
-	// Constructed a complete matrix, so we can start!
-	log(matrix2string(m))
-
 	// Solve matrix now
 	eliminateGaussJordan(m)
 
@@ -471,7 +434,6 @@ Float function step_simulation(model : Element, schedule : Element, time : Float
 
 		if (list_len(scc) > 1):
 			if (bool_not(solve_scc(model, scc))):
-				log("ALGEBRAIC_LOOP")
 				output("ALGEBRAIC_LOOP")
 				return time!
 		else:
@@ -479,7 +441,6 @@ Float function step_simulation(model : Element, schedule : Element, time : Float
 
 			// Execute "block"
 			blocktype = read_type(model, block)
-			//log("Execute block " + block + " : " + blocktype)
 			incoming = set_copy(inputs[block])
 			if (blocktype == "FullRuntime/ConstantBlock"):
 				signal = cast_float(read_attribute(model, block, "value"))