Browse Source

Live modelling of CBDs is mostly working, but changes are not propagated due to lack of traceability model in current PM

Yentl Van Tendeloo 7 years ago
parent
commit
008cd10561

BIN
bootstrap/bootstrap.m.gz


+ 3 - 28
bootstrap/core_algorithm.alc

@@ -91,7 +91,6 @@ Element function get_full_model(model_id : String, metamodel_id : String):
 	Element m
 	Element all_links
 	String choice
-	log("Reading full model of " + cast_string(read_attribute(core, model_id, "name")))
 
 	choice = get_instanceOf_link(model_id, metamodel_id)
 
@@ -382,19 +381,15 @@ String function store_entry(model_id : String, full_name : String, user_id : Str
 	return full_name!
 
 String function export_typing(model : Element, name : String):
-	log("Export typing of model with name " + name)
 	String result
 	result = instantiate_node(core, "TypeMapping", "")
 	name = "type mappings/" + name
 
 	// Create type mapping model
-	log("OK")
-	log("Model: " + cast_id(model))
 	String location
 	location = "type mappings/" + cast_id(get_type_mapping(model))
 	export_node(location, get_type_mapping(model))
 
-	log("Creating new instance of")
 	String instance_of
 	name = store_entry(result, name, get_user_id("admin"))
 	instantiate_attribute(core, result, "name", name)
@@ -404,7 +399,6 @@ String function export_typing(model : Element, name : String):
 	instantiate_link(core, "group", "", result, get_group_id("nobody"))
 	instance_of = instantiate_link(core, "instanceOf", "", result, get_entry_id("formalisms/TypeMapping"))
 	instantiate_link(core, "semantics", "", instance_of, get_entry_id("models/conformance_mv"))
-	log("Export OK")
 
 	return result!
 
@@ -450,12 +444,10 @@ Void function model_overwrite(model : Element, model_id : String, metamodel_id :
 	if (element_neq(choice, read_root())):
 		// There was a link, so we remove it
 
-		log("Remove previous instanceOf link")
 		// First remove the type mapping it referred to
 		Element tl
 		tl = allAssociationDestinations(core, choice, "typing")
 		while (set_len(tl) > 0):
-			log("Remove typing")
 			model_delete_element(core, set_pop(tl))
 
 		// Now delete the element itself
@@ -639,11 +631,6 @@ Element function execute_operation(operation_id : String, input_models : Element
 		edge = set_pop(iter)
 		dict_add(output_metamodels, read_attribute(core, edge, "name"), full_name(readAssociationDestination(core, edge)))
 
-	log("Input models: " + dict_to_string(input_models))
-	log("Found signature:")
-	log("Input: " + dict_to_string(input_metamodels))
-	log("Output: " + dict_to_string(output_metamodels))
-	
 	// 1) Find merged metamodel
 
 	exact_type = read_type(core, operation_id)
@@ -662,11 +649,7 @@ Element function execute_operation(operation_id : String, input_models : Element
 		while (set_len(keys) > 0):
 			key = set_pop(keys)
 			Element mm
-			log("Getting full model for " + key)
-			log("Input: " + get_entry_id(input_models[key]))
-			log("Input MM: " + get_entry_id(input_metamodels[key]))
 			mm = get_full_model(get_entry_id(input_models[key]), get_entry_id(input_metamodels[key]))
-			log("Success!")
 			if (element_eq(mm, read_root())):
 				log("Signature mismatch in operation for tag " + key)
 				output("Signature mismatch in operation for tag " + key)
@@ -680,7 +663,6 @@ Element function execute_operation(operation_id : String, input_models : Element
 			output("Merged metamodel in operation is not of type formalisms/SimpleClassDiagrams")
 			return read_root()!
 
-		log("Joining")
 		merged_model = model_join(model_tuples, merged_metamodel, tracability_model)
 	else:
 		if (bool_and(dict_len(input_models) == 1, dict_len(output_metamodels) == 0)):
@@ -701,7 +683,6 @@ Element function execute_operation(operation_id : String, input_models : Element
 
 	// 3) Transform
 
-	log("Start transform")
 	if (exact_type == "ModelTransformation"):
 		trace_links = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
 		ramified_metamodel_id = ""
@@ -744,7 +725,6 @@ Element function execute_operation(operation_id : String, input_models : Element
 		output("Unknown type of operation: " + exact_type)
 		return read_root()!
 
-	log("OK, now split for " + cast_string(read_attribute(core, operation_id, "name")))
 	// 4) Split in different models depending on type
 
 	if (element_neq(tracability_model, read_root())):
@@ -765,10 +745,7 @@ Element function execute_operation(operation_id : String, input_models : Element
 				return read_root()!
 			set_add_node(model_tuples, create_tuple(key, mm))
 
-		log("Split!")
 		result = model_split(merged_model, model_tuples, tracability)
-		log("Split OK")
-		log("Result: " + dict_to_string(result))
 
 		if (tracability):
 			Element new_tracability_model
@@ -874,7 +851,10 @@ Element function PM_signature(pm : Element):
 Void function enact_PM_activity(activity_to_task : Element, task_to_result : Element, pm : Element, element : String, mapping : Element):
 	Boolean result
 	pm_tasks = activity_to_task
+	log("Spawned activity with ID " + element)
+	log("Assigned to global pm_tasks: " + dict_to_string(pm_tasks))
 	set_add(activity_to_task[element], get_taskname())
+	log("Simulation activities: " + set_to_string(pm_tasks["simulate"]))
 	log("Spawn task for activity " + cast_string(read_attribute(pm, element, "name")))
 	result = enact_action(pm, element, mapping)
 	dict_add_fast(task_to_result, get_taskname(), result)
@@ -1035,10 +1015,8 @@ Void function enact_PM(pm : Element, mapping : Element):
 				sleep(0.1)
 
 	// Remove all mock locations again
-	log("Cleaning up")
 	while (set_len(mock_locations) > 0):
 		model_delete(get_entry_id(set_pop(mock_locations)))
-	log("Models cleaned up")
 
 	return !
 
@@ -1149,7 +1127,6 @@ String function cmd_process_execute(process : String, mapping : Element):
 				return "Specified model cannot be interpreted as a ProcessModel: " + process!
 
 			enact_PM(pm, mapping)
-			log("Finishing process execute")
 			return "Success"!
 		else:
 			return "Permission denied to model: " + process!
@@ -1439,7 +1416,6 @@ Void function spawn_activity(returnvalue : Element, transformation_id : String,
 	if (element_eq(result, read_root())):
 		// Something went wrong!
 		set_add(returnvalue, False)
-		log("FAILURE")
 		output("Failure")
 	else:
 		keys = dict_keys(outputs)
@@ -1453,7 +1429,6 @@ Void function spawn_activity(returnvalue : Element, transformation_id : String,
 				model_overwrite(result[key], get_entry_id(outputs[key]), get_entry_id(output_map[key]))
 
 		set_add(returnvalue, True)
-		log("SUCCESS")
 		output("Success")
 
 	while (other_has_output(get_taskname())):

+ 0 - 4
interface/simple_plot/main.py

@@ -33,10 +33,8 @@ while 1:
         l = first
         first = None
     else:
-        print("Wait for input")
         l = raw_input()
 
-    print("Plotting values: " + l)
     if l == "CLOSE":
         import sys
         sys.exit(0)
@@ -53,11 +51,9 @@ while 1:
         plt.legend()
         d[key] = ([], [])
 
-    print("Update")
     d[key][0].append(time)
     d[key][1].append(value)
     maps[key].set_xdata(d[key][0])
     maps[key].set_ydata(d[key][1])
-    print("Drawing")
     plt.draw()
     write_data((0.0, d))

+ 2 - 2
models/cbd_merge.alc

@@ -29,7 +29,7 @@ Boolean function main(model : Element):
 		element_name = set_pop(all_blocks)
 		if (set_len(allOutgoingAssociationInstances(model, element_name, "P2F_block")) > 0):
 			// Element already exists in full, so copy existing attributes
-			log("Found existing element!")
+			log("Found existing element of type " + read_type(model, element_name))
             if (is_nominal_instance(model, element_name, "PartialRuntime/ICBlock")):
                 instantiate_attribute(model, element_name, "last_in", read_attribute(model, map_P2F(model, element_name), "last_in"))
             if (is_nominal_instance(model, element_name, "PartialRuntime/IntegratorBlock")):
@@ -37,7 +37,7 @@ Boolean function main(model : Element):
             instantiate_attribute(model, element_name, "signal", read_attribute(model, map_P2F(model, element_name), "signal"))
 		else:
 			// Element doesn't exist, so initialize with 0.0
-			log("Initializing new element")
+			log("Initializing new element of type " + read_type(model, element_name))
             instantiate_attribute(model, element_name, "signal", 0.0)
 			instantiate_link(model, "P2F_block", "", element_name, element_name)
 

+ 3 - 0
models/cbd_simulate.alc

@@ -18,6 +18,8 @@ Boolean function main(model : Element):
 	time = set_pop(allInstances(model, "FullRuntime/Time"))
 	current_time = read_attribute(model, time, "current_time")
 
+	log("Probe blocks: " + cast_string(set_len(allInstances(model, "FullRuntime/ProbeBlock"))))
+
 	schedule_init = create_schedule(model)
 	schedule_run = read_root()
 
@@ -32,6 +34,7 @@ Boolean function main(model : Element):
 
 	log("Finishing simulation, as we got input!")
 	instantiate_attribute(model, time, "current_time", current_time)
+	output("CLOSE")
 	return True!
 
 Element function create_schedule(model : Element):

+ 2 - 5
models/cbd_toRuntime.alc

@@ -7,7 +7,6 @@ String function map_D2P(model : Element, name : String):
 	String pick
 
 	destinations = allAssociationDestinations(model, name, "D2P_block")
-	log("Got destinations: " + set_to_string(destinations))
 
 	pick = name
 	while (pick == name):
@@ -31,7 +30,7 @@ Boolean function main(model : Element):
 			// New design element, so create in partial runtime model as well
 			new_element_name = instantiate_node(model, mm_type_name, "")
 			instantiate_link(model, "D2P_block", "", element_name, new_element_name)
-			log("Create link to element " + new_element_name)
+			log("Found new design element of type " + mm_type_name)
 
 		// Always update the value of attributes of PartialRuntime
 		new_element_name = map_D2P(model, element_name)
@@ -46,6 +45,7 @@ Boolean function main(model : Element):
 		if (set_len(allIncomingAssociationInstances(model, element_name, "D2P_block")) == 0):
 			// Old partial runtime element, so remove
 			model_delete_element(model, element_name)
+			log("Removing unconnected Partial element of type " + read_type(model, element_name))
 
 	// Delete all existing links
 	all_links = allInstances(model, "PartialRuntime/Link")
@@ -61,9 +61,6 @@ Boolean function main(model : Element):
     while (set_len(all_links) > 0):
         element_name = set_pop(all_links)
         instantiate_link(model, "PartialRuntime/Link", "", map_D2P(model, readAssociationSource(model, element_name)), map_D2P(model, readAssociationDestination(model, element_name)))
-		log("Create Link")
-		log("   from: " + map_D2P(model, readAssociationSource(model, element_name)))
-		log("     to: " + map_D2P(model, readAssociationDestination(model, element_name)))
 
     all_links = allInstances(model, "Design/InitialCondition")
     while (set_len(all_links) > 0):

+ 1 - 2
models/pm_live_CBD.mvc

@@ -48,8 +48,7 @@ Data full_runtime_model {
 
 Next (start, toRuntime_0) {}
 Next (toRuntime_0, merge_0) {}
-Next (merge_0, simulate) {}
-
+Next (merge_0, fork1) {}
 Next (fork1, edit) {}
 Next (fork1, simulate) {}
 Next (edit, toRuntime) {}

+ 12 - 1
models/upload_models.py

@@ -31,7 +31,18 @@ transformation_add_AL({}, {}, "models/CBD/restartSim", open("models/cbd_restartS
 
 model_add("models/live_modelling_CBD", "formalisms/ProcessModel", open("models/pm_live_CBD.mvc", 'r').read())
 
-process_execute("models/live_modelling_CBD", {"design_model": "models/CBD_spring", "partial_runtime_model": "models/cbd_empty_partial", "full_runtime_model": "models/cbd_empty_full"}, {})
+def modify_model(model):
+    if len(all_instances(model, "Design/ProbeBlock")) > 2:
+        import time
+        print("Sufficient Probeblocks detected, so pausing with edits")
+        while 1:
+            time.sleep(1)
+
+    new_block = instantiate(model, "Design/ProbeBlock")
+    attr_assign(model, new_block, "name", "MyProbeBlock")
+    print("Added new probeblock: " + new_block)
+
+process_execute("models/live_modelling_CBD", {"design_model": "models/CBD_spring", "partial_runtime_model": "models/cbd_empty_partial", "full_runtime_model": "models/cbd_empty_full"}, {"models/CBD/edit": modify_model})
 
 """
 model_add("formalisms/PW_Plant", "formalisms/SimpleClassDiagrams", open("models/plant_PW.mvc", 'r').read())

+ 0 - 3
wrappers/modelverse.py

@@ -453,12 +453,9 @@ def process_execute(process_name, model_mapping, callbacks=None):
     INPUT("process_execute", None, [process_name, model_mapping])
 
     while 1:
-        print("Waiting for output...")
         result = OUTPUT()
-        print("Got result: " + str(result))
         if result == "Success":
             # Finished
-            print("FINISHING")
             return None
         else:
             taskname, operation = result

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
-Date:   Thu Nov 16 13:02:20 2017
+Date:   Thu Nov 16 15:55:38 2017
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server