瀏覽代碼

Working live modelling!

Yentl Van Tendeloo 7 年之前
父節點
當前提交
1a4862cdd8

二進制
bootstrap/bootstrap.m.gz


+ 0 - 5
bootstrap/core_algorithm.alc

@@ -881,14 +881,9 @@ 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")))
 	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)
-	log("Finished task for activity " + cast_string(read_attribute(pm, element, "name")))
 
 
 	while (other_has_output(get_taskname())):
 	while (other_has_output(get_taskname())):
 		sleep(1)
 		sleep(1)

+ 1 - 1
bootstrap/model_management.alc

@@ -194,7 +194,6 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 			src_name = read_attribute(tracability_model, readAssociationSource(tracability_model, tracability_link), "name")
 			src_name = read_attribute(tracability_model, readAssociationSource(tracability_model, tracability_link), "name")
 			dst_name = read_attribute(tracability_model, readAssociationDestination(tracability_model, tracability_link), "name")
 			dst_name = read_attribute(tracability_model, readAssociationDestination(tracability_model, tracability_link), "name")
 
 
-			log("Drawing tracability link from " + src_name + " to " + dst_name)
 			type = read_attribute(tracability_model, tracability_link, "type")
 			type = read_attribute(tracability_model, tracability_link, "type")
 
 
 			// Now try to find all possible combinations
 			// Now try to find all possible combinations
@@ -213,6 +212,7 @@ Element function model_join(models : Element, metamodel : Element, tracability_m
 						if (dict_in(new_model["model"], dst_model + dst_name)):
 						if (dict_in(new_model["model"], dst_model + dst_name)):
 							// Found a match for source and target, so create a link
 							// Found a match for source and target, so create a link
 							new_name = instantiate_link(new_model, type, "", src_model + src_name, dst_model + dst_name)
 							new_name = instantiate_link(new_model, type, "", src_model + src_name, dst_model + dst_name)
+
 							if (new_name == ""):
 							if (new_name == ""):
 								log("ERROR: could not create a tracability link; ignoring")
 								log("ERROR: could not create a tracability link; ignoring")
 	return new_model!
 	return new_model!

+ 7 - 2
bootstrap/modelling.alc

@@ -449,15 +449,20 @@ Void function unset_attribute(model : Element, element : String, attribute : Str
 	String attr_type
 	String attr_type
 	Element attr_links
 	Element attr_links
 	String attr_link
 	String attr_link
+	String attr_value
 	
 	
 	attr_type = find_attribute_type(model, element, attribute)
 	attr_type = find_attribute_type(model, element, attribute)
 	attr_links = allOutgoingAssociationInstances(model, element, attr_type)
 	attr_links = allOutgoingAssociationInstances(model, element, attr_type)
 
 
 	while (set_len(attr_links) > 0):
 	while (set_len(attr_links) > 0):
 		attr_link = set_pop(attr_links)
 		attr_link = set_pop(attr_links)
-		remove_type(model, reverseKeyLookup(model["model"], read_edge_dst(model["model"][attr_link])))
+		attr_value = readAssociationDestination(model, attr_link)
 		remove_type(model, attr_link)
 		remove_type(model, attr_link)
-		dict_delete(model["model"], reverseKeyLookup(model["model"], read_edge_dst(model["model"][attr_link])))
+		
+		if (dict_in(model["model"], attr_value)):
+			remove_type(model, attr_value)
+			dict_delete(model["model"], attr_value)
+
 		delete_element(model["model"][attr_link])
 		delete_element(model["model"][attr_link])
 
 
 	return!
 	return!

+ 2 - 1
bootstrap/typing.alc

@@ -89,7 +89,8 @@ Void function new_type_mapping(model : Element):
 	return !
 	return !
 
 
 Void function remove_type(model : Element, name : String):
 Void function remove_type(model : Element, name : String):
-	dict_delete(model["type_mapping"], name)
+	if (dict_in(model["type_mapping"], name)):
+		dict_delete(model["type_mapping"], name)
 	
 	
 	String elem
 	String elem
 	elem = cast_id(model["model"][name])
 	elem = cast_id(model["model"][name])

+ 1 - 1
kernel/modelverse_kernel/primitives.py

@@ -208,7 +208,7 @@ def dict_delete(a, b, **remainder):
     b_value, = yield [("RV", [b])]
     b_value, = yield [("RV", [b])]
     edge, = yield [("RDE", [a, b_value])]
     edge, = yield [("RDE", [a, b_value])]
     if edge is None:
     if edge is None:
-        print("Failed dict_delete for value %s!" % b_value)
+        print("Failed dict_delete for value '%s'!" % b_value)
         keys, = yield [("RDK", [a])]
         keys, = yield [("RDK", [a])]
         keys = yield [("RV", [i]) for i in keys]
         keys = yield [("RV", [i]) for i in keys]
         print("Keys: " + str(keys))
         print("Keys: " + str(keys))

+ 2 - 4
models/cbd_merge.alc

@@ -11,11 +11,11 @@ String function map_P2F(model : Element, name : String):
 	String pick
 	String pick
 
 
 	destinations = allAssociationDestinations(model, name, "P2F_block")
 	destinations = allAssociationDestinations(model, name, "P2F_block")
-	log("Got destinations: " + set_to_string(destinations))
 
 
 	pick = name
 	pick = name
-	while (pick != name):
+	while (pick == name):
 		pick = set_pop(destinations)
 		pick = set_pop(destinations)
+
 	return pick!
 	return pick!
 
 
 Boolean function main(model : Element):
 Boolean function main(model : Element):
@@ -29,7 +29,6 @@ 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 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 +36,6 @@ 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 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)
 
 

+ 4 - 14
models/cbd_simulate.alc

@@ -18,8 +18,6 @@ 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,7 +30,6 @@ Boolean function main(model : Element):
 			schedule = schedule_run
 			schedule = schedule_run
 		current_time = step_simulation(model, schedule, current_time)
 		current_time = step_simulation(model, schedule, current_time)
 
 
-	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")
 	output("CLOSE")
 	return True!
 	return True!
@@ -57,7 +54,7 @@ Element function create_schedule(model : Element):
 			dict_add(predecessors, element_name, create_node())
 			dict_add(predecessors, element_name, create_node())
 
 
 		if (is_nominal_instance(model, element_name, "FullRuntime/ICBlock")):
 		if (is_nominal_instance(model, element_name, "FullRuntime/ICBlock")):
-			if (element_eq(read_attribute(model, element_name, "last_in"), read_root())):
+			if (bool_not(is_physical_float(read_attribute(model, element_name, "last_in")))):
 				incoming_links = allIncomingAssociationInstances(model, element_name, "FullRuntime/InitialCondition")
 				incoming_links = allIncomingAssociationInstances(model, element_name, "FullRuntime/InitialCondition")
 			else:
 			else:
 				incoming_links = create_node()
 				incoming_links = create_node()
@@ -186,11 +183,9 @@ Boolean function solve_scc(model : Element, scc : Element):
 		list_append(m, t)
 		list_append(m, t)
 		i = i + 1
 		i = i + 1
 
 
-	log("Matrix ready!")
 	// Matrix initialized to 0.0
 	// Matrix initialized to 0.0
 	i = 0
 	i = 0
 	while (i < read_nr_out(scc)):
 	while (i < read_nr_out(scc)):
-		log("Creating matrix row")
 		// First element of scc
 		// First element of scc
 		block = scc[i]
 		block = scc[i]
 		blocktype = read_type(model, block)
 		blocktype = read_type(model, block)
@@ -204,15 +199,11 @@ Boolean function solve_scc(model : Element, scc : Element):
 		elif (blocktype == "FullRuntime/MultiplyBlock"):
 		elif (blocktype == "FullRuntime/MultiplyBlock"):
 			constant = 1.0
 			constant = 1.0
 
 
-		log("Generating matrix for " + blocktype)
-		log("Block: " + block)
 		incoming = allIncomingAssociationInstances(model, block, "Link")
 		incoming = allIncomingAssociationInstances(model, block, "Link")
 
 
 		Integer index_to_write_constant
 		Integer index_to_write_constant
 		index_to_write_constant = -1
 		index_to_write_constant = -1
-		log("Iterating over incoming")
 		while (read_nr_out(incoming) > 0):
 		while (read_nr_out(incoming) > 0):
-			log("Iteration")
 			selected = readAssociationSource(model, set_pop(incoming))
 			selected = readAssociationSource(model, set_pop(incoming))
 
 
 			if (set_in(scc, selected)):
 			if (set_in(scc, selected)):
@@ -260,7 +251,6 @@ Boolean function solve_scc(model : Element, scc : Element):
 		i = i + 1
 		i = i + 1
 
 
 	// Constructed a complete matrix, so we can start!
 	// Constructed a complete matrix, so we can start!
-	log("Constructed matrix to solve:")
 	log(matrix2string(m))
 	log(matrix2string(m))
 
 
 	// Solve matrix now
 	// Solve matrix now
@@ -344,7 +334,7 @@ Float function step_simulation(model : Element, schedule : Element, time : Float
 					signal = float_division(1.0, cast_float(read_attribute(model, selected, "signal")))
 					signal = float_division(1.0, cast_float(read_attribute(model, selected, "signal")))
 			elif (blocktype == "FullRuntime/DelayBlock"):
 			elif (blocktype == "FullRuntime/DelayBlock"):
 				signal = 0.0
 				signal = 0.0
-				if (element_eq(read_attribute(model, block, "last_in"), read_root())):
+				if (bool_not(is_physical_float(read_attribute(model, block, "last_in")))):
 					// No memory yet, so use initial condition
 					// No memory yet, so use initial condition
 					incoming = allAssociationOrigins(model, block, "FullRuntime/InitialCondition")
 					incoming = allAssociationOrigins(model, block, "FullRuntime/InitialCondition")
 					while (set_len(incoming) > 0):
 					while (set_len(incoming) > 0):
@@ -354,7 +344,7 @@ Float function step_simulation(model : Element, schedule : Element, time : Float
 					signal = read_attribute(model, block, "last_in")
 					signal = read_attribute(model, block, "last_in")
 				set_add(memory_blocks, block)
 				set_add(memory_blocks, block)
 			elif (blocktype == "FullRuntime/IntegratorBlock"):
 			elif (blocktype == "FullRuntime/IntegratorBlock"):
-				if (element_eq(read_attribute(model, block, "last_in"), read_root())):
+				if (bool_not(is_physical_float(read_attribute(model, block, "last_in")))):
 					// No history yet, so use initial values
 					// No history yet, so use initial values
 					incoming = allAssociationOrigins(model, block, "FullRuntime/InitialCondition")
 					incoming = allAssociationOrigins(model, block, "FullRuntime/InitialCondition")
 					while (set_len(incoming) > 0):
 					while (set_len(incoming) > 0):
@@ -365,7 +355,7 @@ Float function step_simulation(model : Element, schedule : Element, time : Float
 				instantiate_attribute(model, block, "last_out", signal)
 				instantiate_attribute(model, block, "last_out", signal)
 				set_add(memory_blocks, block)
 				set_add(memory_blocks, block)
 			elif (blocktype == "FullRuntime/DerivatorBlock"):
 			elif (blocktype == "FullRuntime/DerivatorBlock"):
-				if (element_eq(read_attribute(model, block, "last_in"), read_root())):
+				if (bool_not(is_physical_float(read_attribute(model, block, "last_in")))):
 					// No history yet, so use initial values
 					// No history yet, so use initial values
 					incoming = allAssociationOrigins(model, block, "FullRuntime/InitialCondition")
 					incoming = allAssociationOrigins(model, block, "FullRuntime/InitialCondition")
 					while (set_len(incoming) > 0):
 					while (set_len(incoming) > 0):

+ 0 - 2
models/cbd_toRuntime.alc

@@ -30,7 +30,6 @@ 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("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)
@@ -45,7 +44,6 @@ 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")

+ 3 - 0
models/pm_live_CBD.mvc

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

+ 1 - 1
models/upload_models.py

@@ -20,7 +20,7 @@ transformation_add_MANUAL({"Design": "formalisms/CBD/Design_MM"}, {"Design": "fo
 def trace_D2P(model):
 def trace_D2P(model):
     instantiate(model, "Association", ("Design/Block", "PartialRuntime/Block"), ID="D2P_block")
     instantiate(model, "Association", ("Design/Block", "PartialRuntime/Block"), ID="D2P_block")
 
 
-transformation_add_AL({"Design": "formalisms/CBD/Design_MM"}, {"PartialRuntime": "formalisms/CBD/PartialRuntime_MM"}, "models/CBD/toRuntime", open("models/cbd_toRuntime.alc", 'r').read(), trace_D2P)
+transformation_add_AL({"Design": "formalisms/CBD/Design_MM", "PartialRuntime": "formalisms/CBD/PartialRuntime_MM"}, {"PartialRuntime": "formalisms/CBD/PartialRuntime_MM"}, "models/CBD/toRuntime", open("models/cbd_toRuntime.alc", 'r').read(), trace_D2P)
 
 
 def trace_P2F(model):
 def trace_P2F(model):
     instantiate(model, "Association", ("PartialRuntime/Block", "FullRuntime/Block"), ID="P2F_block")
     instantiate(model, "Association", ("PartialRuntime/Block", "FullRuntime/Block"), ID="P2F_block")

+ 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:   Fri Nov 17 07:56:27 2017
+Date:   Fri Nov 17 09:42:18 2017
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server