浏览代码

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 年之前
父节点
当前提交
008cd10561

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

+ 0 - 4
interface/simple_plot/main.py

@@ -33,10 +33,8 @@ while 1:
         l = first
         l = first
         first = None
         first = None
     else:
     else:
-        print("Wait for input")
         l = raw_input()
         l = raw_input()
 
 
-    print("Plotting values: " + l)
     if l == "CLOSE":
     if l == "CLOSE":
         import sys
         import sys
         sys.exit(0)
         sys.exit(0)
@@ -53,11 +51,9 @@ while 1:
         plt.legend()
         plt.legend()
         d[key] = ([], [])
         d[key] = ([], [])
 
 
-    print("Update")
     d[key][0].append(time)
     d[key][0].append(time)
     d[key][1].append(value)
     d[key][1].append(value)
     maps[key].set_xdata(d[key][0])
     maps[key].set_xdata(d[key][0])
     maps[key].set_ydata(d[key][1])
     maps[key].set_ydata(d[key][1])
-    print("Drawing")
     plt.draw()
     plt.draw()
     write_data((0.0, d))
     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)
 		element_name = set_pop(all_blocks)
 		if (set_len(allOutgoingAssociationInstances(model, element_name, "P2F_block")) > 0):
 		if (set_len(allOutgoingAssociationInstances(model, element_name, "P2F_block")) > 0):
 			// Element already exists in full, so copy existing attributes
 			// 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")):
             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"))
                 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")):
             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"))
             instantiate_attribute(model, element_name, "signal", read_attribute(model, map_P2F(model, element_name), "signal"))
 		else:
 		else:
 			// Element doesn't exist, so initialize with 0.0
 			// 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_attribute(model, element_name, "signal", 0.0)
 			instantiate_link(model, "P2F_block", "", element_name, element_name)
 			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"))
 	time = set_pop(allInstances(model, "FullRuntime/Time"))
 	current_time = read_attribute(model, time, "current_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_init = create_schedule(model)
 	schedule_run = read_root()
 	schedule_run = read_root()
 
 
@@ -32,6 +34,7 @@ Boolean function main(model : Element):
 
 
 	log("Finishing simulation, as we got input!")
 	log("Finishing simulation, as we got input!")
 	instantiate_attribute(model, time, "current_time", current_time)
 	instantiate_attribute(model, time, "current_time", current_time)
+	output("CLOSE")
 	return True!
 	return True!
 
 
 Element function create_schedule(model : Element):
 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
 	String pick
 
 
 	destinations = allAssociationDestinations(model, name, "D2P_block")
 	destinations = allAssociationDestinations(model, name, "D2P_block")
-	log("Got destinations: " + set_to_string(destinations))
 
 
 	pick = name
 	pick = name
 	while (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 design element, so create in partial runtime model as well
 			new_element_name = instantiate_node(model, mm_type_name, "")
 			new_element_name = instantiate_node(model, mm_type_name, "")
 			instantiate_link(model, "D2P_block", "", element_name, new_element_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
 		// Always update the value of attributes of PartialRuntime
 		new_element_name = map_D2P(model, element_name)
 		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):
 		if (set_len(allIncomingAssociationInstances(model, element_name, "D2P_block")) == 0):
 			// Old partial runtime element, so remove
 			// Old partial runtime element, so remove
 			model_delete_element(model, element_name)
 			model_delete_element(model, element_name)
+			log("Removing unconnected Partial element of type " + read_type(model, element_name))
 
 
 	// Delete all existing links
 	// Delete all existing links
 	all_links = allInstances(model, "PartialRuntime/Link")
 	all_links = allInstances(model, "PartialRuntime/Link")
@@ -61,9 +61,6 @@ Boolean function main(model : Element):
     while (set_len(all_links) > 0):
     while (set_len(all_links) > 0):
         element_name = set_pop(all_links)
         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)))
         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")
     all_links = allInstances(model, "Design/InitialCondition")
     while (set_len(all_links) > 0):
     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 (start, toRuntime_0) {}
 Next (toRuntime_0, merge_0) {}
 Next (toRuntime_0, merge_0) {}
-Next (merge_0, simulate) {}
-
+Next (merge_0, fork1) {}
 Next (fork1, edit) {}
 Next (fork1, edit) {}
 Next (fork1, simulate) {}
 Next (fork1, simulate) {}
 Next (edit, toRuntime) {}
 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())
 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())
 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])
     INPUT("process_execute", None, [process_name, model_mapping])
 
 
     while 1:
     while 1:
-        print("Waiting for output...")
         result = OUTPUT()
         result = OUTPUT()
-        print("Got result: " + str(result))
         if result == "Success":
         if result == "Success":
             # Finished
             # Finished
-            print("FINISHING")
             return None
             return None
         else:
         else:
             taskname, operation = result
             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)
 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 author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server