Browse Source

Working CBD simulation of the spring model

Yentl Van Tendeloo 8 years ago
parent
commit
47419b4375

BIN
bootstrap/bootstrap.m.gz


+ 1 - 1
bootstrap/core_algorithm.alc

@@ -744,7 +744,7 @@ 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")
+	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())):

+ 15 - 3
models/cbd_merge.alc

@@ -4,9 +4,19 @@ include "object_operations.alh"
 include "conformance_scd.alh"
 include "conformance_scd.alh"
 include "utils.alh"
 include "utils.alh"
 include "typing.alh"
 include "typing.alh"
+include "mini_modify.alh"
 
 
 String function map_P2F(model : Element, name : String):
 String function map_P2F(model : Element, name : String):
-	return readAssociationDestination(model, set_pop(allAssociationDestinations(model, name, "P2F_block")))!
+	Element destinations
+	String pick
+
+	destinations = allAssociationDestinations(model, name, "P2F_block")
+	log("Got destinations: " + set_to_string(destinations))
+
+	pick = name
+	while (pick != name):
+		pick = set_pop(destinations)
+	return pick!
 
 
 Boolean function main(model : Element):
 Boolean function main(model : Element):
 	Element all_blocks
 	Element all_blocks
@@ -19,13 +29,15 @@ 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
-            if (is_nominal_instance(model, element_name, "ICBlock")):
+			log("Found existing element!")
+            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, "IntegratorBlock")):
+            if (is_nominal_instance(model, element_name, "PartialRuntime/IntegratorBlock")):
                 instantiate_attribute(model, element_name, "last_out", read_attribute(model, map_P2F(model, element_name), "last_out"))
                 instantiate_attribute(model, element_name, "last_out", read_attribute(model, map_P2F(model, element_name), "last_out"))
             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")
             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)
 
 

+ 110 - 96
models/cbd_simulate.alc

@@ -4,6 +4,7 @@ include "object_operations.alh"
 include "conformance_scd.alh"
 include "conformance_scd.alh"
 include "io.alh"
 include "io.alh"
 include "metamodels.alh"
 include "metamodels.alh"
+include "mini_modify.alh"
 
 
 Boolean function main(model : Element):
 Boolean function main(model : Element):
 	String cmd
 	String cmd
@@ -11,76 +12,109 @@ Boolean function main(model : Element):
 	Element schedule_init
 	Element schedule_init
 	Element schedule_run
 	Element schedule_run
 	Element schedule
 	Element schedule
-	String conforming
-	log("Start simulation of model!")
+	Float current_time
+
+	String time
+	time = set_pop(allInstances(model, "FullRuntime/Time"))
+	current_time = read_attribute(model, time, "current_time")
 
 
 	schedule_init = create_schedule(model)
 	schedule_init = create_schedule(model)
 	schedule_run = read_root()
 	schedule_run = read_root()
 
 
 	while (bool_not(has_input())):
 	while (bool_not(has_input())):
-		if (read_attribute(model, "time", "start_time") == read_attribute(model, "time", "current_time")):
+		if (read_attribute(model, time, "start_time") == read_attribute(model, time, "current_time")):
 			schedule = schedule_init
 			schedule = schedule_init
 		else:
 		else:
 			if (element_eq(schedule_run, read_root())):
 			if (element_eq(schedule_run, read_root())):
 				schedule_run = create_schedule(model)
 				schedule_run = create_schedule(model)
 			schedule = schedule_run
 			schedule = schedule_run
-		//schedule = create_schedule(model)
-		step_simulation(model, schedule)
+		current_time = step_simulation(model, schedule, current_time)
 
 
 	log("Finishing simulation, as we got input!")
 	log("Finishing simulation, as we got input!")
+	instantiate_attribute(model, time, "current_time", current_time)
 	return True!
 	return True!
 
 
 Element function create_schedule(model : Element):
 Element function create_schedule(model : Element):
 	// Create nice graph first
 	// Create nice graph first
 	Element nodes
 	Element nodes
 	Element successors
 	Element successors
+	Element predecessors
 	String element_name
 	String element_name
 	Element incoming_links
 	Element incoming_links
 	Element all_blocks
 	Element all_blocks
 
 
-	nodes = allInstances(model, "Block")
-	successors = create_node()
-	while (read_nr_out(nodes) > 0):
+	nodes = allInstances(model, "FullRuntime/Block")
+	successors = dict_create()
+	predecessors = dict_create()
+	while (set_len(nodes) > 0):
 		element_name = set_pop(nodes)
 		element_name = set_pop(nodes)
 		if (bool_not(dict_in(successors, element_name))):
 		if (bool_not(dict_in(successors, element_name))):
 			dict_add(successors, element_name, create_node())
 			dict_add(successors, element_name, create_node())
+		if (bool_not(dict_in(predecessors, element_name))):
+			dict_add(predecessors, element_name, create_node())
 
 
-		if (is_nominal_instance(model, element_name, "ICBlock")):
+		if (is_nominal_instance(model, element_name, "FullRuntime/ICBlock")):
 			if (element_eq(read_attribute(model, element_name, "last_in"), read_root())):
 			if (element_eq(read_attribute(model, element_name, "last_in"), read_root())):
-				incoming_links = allIncomingAssociationInstances(model, element_name, "InitialCondition")
+				incoming_links = allIncomingAssociationInstances(model, element_name, "FullRuntime/InitialCondition")
 			else:
 			else:
 				incoming_links = create_node()
 				incoming_links = create_node()
-			if (is_nominal_instance(model, element_name, "DerivatorBlock")):
+			if (is_nominal_instance(model, element_name, "FullRuntime/DerivatorBlock")):
 				Element new_incoming_links
 				Element new_incoming_links
-				new_incoming_links = allIncomingAssociationInstances(model, element_name, "Link")
+				new_incoming_links = allIncomingAssociationInstances(model, element_name, "FullRuntime/Link")
 				while (read_nr_out(new_incoming_links) > 0):
 				while (read_nr_out(new_incoming_links) > 0):
 					list_append(incoming_links, set_pop(new_incoming_links))
 					list_append(incoming_links, set_pop(new_incoming_links))
 		else:
 		else:
-			incoming_links = allIncomingAssociationInstances(model, element_name, "Link")
+			incoming_links = allIncomingAssociationInstances(model, element_name, "FullRuntime/Link")
 
 
-		while (read_nr_out(incoming_links) > 0):
+		while (set_len(incoming_links) > 0):
 			String source
 			String source
 			source = readAssociationSource(model, set_pop(incoming_links))
 			source = readAssociationSource(model, set_pop(incoming_links))
 			if (bool_not(dict_in(successors, source))):
 			if (bool_not(dict_in(successors, source))):
 				dict_add(successors, source, create_node())
 				dict_add(successors, source, create_node())
 			set_add(successors[source], element_name)
 			set_add(successors[source], element_name)
+			set_add(predecessors[element_name], source)
 	
 	
 	Element values
 	Element values
 	values = create_node()
 	values = create_node()
+	dict_add(values, "model", model)
 	dict_add(values, "S", create_node())
 	dict_add(values, "S", create_node())
 	dict_add(values, "index", 0)
 	dict_add(values, "index", 0)
 	dict_add(values, "indices", create_node())
 	dict_add(values, "indices", create_node())
 	dict_add(values, "lowlink", create_node())
 	dict_add(values, "lowlink", create_node())
 	dict_add(values, "onStack", create_node())
 	dict_add(values, "onStack", create_node())
 	dict_add(values, "successors", successors)
 	dict_add(values, "successors", successors)
+	dict_add(values, "predecessors", predecessors)
 	dict_add(values, "SCC", create_node())
 	dict_add(values, "SCC", create_node())
 
 
-	nodes = allInstances(model, "Block")
-	while (read_nr_out(nodes) > 0):
-		strongconnect(set_pop(nodes), values)
+	nodes = get_topolist(values)
+	while (list_len(nodes) > 0):
+		strongconnect(list_pop_final(nodes), values)
 
 
 	return values["SCC"]!
 	return values["SCC"]!
 
 
+Element function get_topolist(values : Element):
+	Element result
+	Element predecessors
+	Element remaining
+	String current_element
+	Element cur_predecessors
+
+	result = list_create()
+	predecessors = dict_copy(values["predecessors"])
+
+	while (dict_len(predecessors) > 0):
+		remaining = dict_keys(predecessors)
+		while (set_len(remaining) > 0):
+			current_element = set_pop(remaining)
+			cur_predecessors = predecessors[current_element]
+			if (set_len(set_overlap(list_to_set(result), cur_predecessors)) == set_len(cur_predecessors)):
+				// All predecessors of this node have already been visited
+				dict_delete(predecessors, current_element)
+				remaining = dict_keys(predecessors)
+				list_append(result, current_element)
+
+	return result!
+
 Integer function min(a : Integer, b : Integer):
 Integer function min(a : Integer, b : Integer):
 	if (a < b):
 	if (a < b):
 		return a!
 		return a!
@@ -101,7 +135,7 @@ Void function strongconnect(v : String, values : Element):
 	Element successors
 	Element successors
 	String w
 	String w
 	successors = values["successors"][v]
 	successors = values["successors"][v]
-	while (read_nr_out(successors) > 0):
+	while (set_len(successors) > 0):
 		w = set_pop(successors)
 		w = set_pop(successors)
 		if (bool_not(dict_in(values["indices"], w))):
 		if (bool_not(dict_in(values["indices"], w))):
 			strongconnect(w, values)
 			strongconnect(w, values)
@@ -125,9 +159,6 @@ Void function strongconnect(v : String, values : Element):
 
 
 	return!
 	return!
 
 
-String function readType(model : Element, name : String):
-	return reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][name]))!
-
 Boolean function solve_scc(model : Element, scc : Element):
 Boolean function solve_scc(model : Element, scc : Element):
 	Element m
 	Element m
 	Integer i
 	Integer i
@@ -159,15 +190,15 @@ Boolean function solve_scc(model : Element, scc : Element):
 		log("Creating matrix row")
 		log("Creating matrix row")
 		// First element of scc
 		// First element of scc
 		block = scc[i]
 		block = scc[i]
-		blocktype = readType(model, block)
+		blocktype = read_type(model, block)
 
 
 		// First write 1 in the current block
 		// First write 1 in the current block
 		dict_overwrite(m[i], i, 1.0)
 		dict_overwrite(m[i], i, 1.0)
 
 
 		// Now check all blocks that are incoming
 		// Now check all blocks that are incoming
-		if (blocktype == "AdditionBlock"):
+		if (blocktype == "FullRuntime/AdditionBlock"):
 			constant = 0.0
 			constant = 0.0
-		elif (blocktype == "MultiplyBlock"):
+		elif (blocktype == "FullRuntime/MultiplyBlock"):
 			constant = 1.0
 			constant = 1.0
 
 
 		log("Generating matrix for " + blocktype)
 		log("Generating matrix for " + blocktype)
@@ -184,21 +215,21 @@ Boolean function solve_scc(model : Element, scc : Element):
 			if (set_in(scc, selected)):
 			if (set_in(scc, selected)):
 				// Part of the loop, so in the index of selected in scc
 				// Part of the loop, so in the index of selected in scc
 				// Five options:
 				// Five options:
-				if (blocktype == "AdditionBlock"):
+				if (blocktype == "FullRuntime/AdditionBlock"):
 					// 1) AdditionBlock
 					// 1) AdditionBlock
 					// Add the negative of this signal, which is as of yet unknown
 					// Add the negative of this signal, which is as of yet unknown
 					// x = y + z --> x - y - z = 0
 					// x = y + z --> x - y - z = 0
 					dict_overwrite(m[i], list_index_of(scc, selected), -1.0)
 					dict_overwrite(m[i], list_index_of(scc, selected), -1.0)
-				elif (blocktype == "MultiplyBlock"):
+				elif (blocktype == "FullRuntime/MultiplyBlock"):
 					// 2) MultiplyBlock
 					// 2) MultiplyBlock
 					if (index_to_write_constant != -1):
 					if (index_to_write_constant != -1):
 						return False!
 						return False!
 					index_to_write_constant = list_index_of(scc, selected)
 					index_to_write_constant = list_index_of(scc, selected)
-				elif (blocktype == "NegatorBlock"):
+				elif (blocktype == "FullRuntime/NegatorBlock"):
 					// 3) NegatorBlock
 					// 3) NegatorBlock
 					// Add the positive of the signal, which is as of yet unknown
 					// Add the positive of the signal, which is as of yet unknown
 					dict_overwrite(m[i], list_index_of(scc, selected), 1.0)
 					dict_overwrite(m[i], list_index_of(scc, selected), 1.0)
-				elif (blocktype == "DelayBlock"):
+				elif (blocktype == "FullRuntime/DelayBlock"):
 					// 5) DelayBlock
 					// 5) DelayBlock
 					// Just copies a single value
 					// Just copies a single value
 					dict_overwrite(m[i], list_index_of(scc, selected), -1.0)
 					dict_overwrite(m[i], list_index_of(scc, selected), -1.0)
@@ -207,10 +238,10 @@ Boolean function solve_scc(model : Element, scc : Element):
 					return False!
 					return False!
 			else:
 			else:
 				// A constant, which we can assume is already computed and thus usable
 				// A constant, which we can assume is already computed and thus usable
-				if (blocktype == "AdditionBlock"):
+				if (blocktype == "FullRuntime/AdditionBlock"):
 					constant = constant + cast_float(read_attribute(model, selected, "signal"))
 					constant = constant + cast_float(read_attribute(model, selected, "signal"))
 					dict_overwrite(m[i], read_nr_out(scc), constant)
 					dict_overwrite(m[i], read_nr_out(scc), constant)
-				elif (blocktype == "MultiplyBlock"):
+				elif (blocktype == "FullRuntime/MultiplyBlock"):
 					constant = constant * cast_float(read_attribute(model, selected, "signal"))
 					constant = constant * cast_float(read_attribute(model, selected, "signal"))
 					// Not written to constant part, as multiplies a variable
 					// Not written to constant part, as multiplies a variable
 
 
@@ -237,7 +268,6 @@ Boolean function solve_scc(model : Element, scc : Element):
 	i = 0
 	i = 0
 	while (i < read_nr_out(m)):
 	while (i < read_nr_out(m)):
 		block = scc[i]
 		block = scc[i]
-		unset_attribute(model, block, "signal")
 		instantiate_attribute(model, block, "signal", m[i][read_nr_out(scc)])
 		instantiate_attribute(model, block, "signal", m[i][read_nr_out(scc)])
 		log((("Solved " + block) + " to ") + cast_string(m[i][read_nr_out(scc)]))
 		log((("Solved " + block) + " to ") + cast_string(m[i][read_nr_out(scc)]))
 		i = i + 1
 		i = i + 1
@@ -254,8 +284,7 @@ Integer function list_index_of(lst : Element, elem : Element):
 			i = i + 1
 			i = i + 1
 	return -1!
 	return -1!
 
 
-Void function step_simulation(model : Element, schedule : Element):
-	String time
+Float function step_simulation(model : Element, schedule : Element, time : Float):
 	Float signal
 	Float signal
 	Element incoming
 	Element incoming
 	String selected
 	String selected
@@ -267,117 +296,102 @@ Void function step_simulation(model : Element, schedule : Element):
 	Float delta_t
 	Float delta_t
 	Element scc
 	Element scc
 
 
-	time = "time"
 	delta_t = 0.1
 	delta_t = 0.1
 
 
-	memory_blocks = create_node()
-	output("SIM_TIME " + cast_string(read_attribute(model, time, "current_time")))
+	memory_blocks = set_create()
 	i = 0
 	i = 0
-	while (i < read_nr_out(schedule)):
+	while (i < list_len(schedule)):
 		scc = list_read(schedule, i)
 		scc = list_read(schedule, i)
 		i = i + 1
 		i = i + 1
 
 
 		if (list_len(scc) > 1):
 		if (list_len(scc) > 1):
-			log("Solving algebraic loop!")
 			if (bool_not(solve_scc(model, scc))):
 			if (bool_not(solve_scc(model, scc))):
 				output("ALGEBRAIC_LOOP")
 				output("ALGEBRAIC_LOOP")
-				return !
+				return time!
 		else:
 		else:
-			block = set_pop(scc)
+			block = list_read(scc, 0)
 
 
 			// Execute "block"
 			// Execute "block"
-			blocktype = readType(model, block)
-			if (blocktype == "ConstantBlock"):
+			blocktype = read_type(model, block)
+			if (blocktype == "FullRuntime/ConstantBlock"):
 				signal = read_attribute(model, block, "value")
 				signal = read_attribute(model, block, "value")
-			elif (blocktype == "AdditionBlock"):
+			elif (blocktype == "FullRuntime/AdditionBlock"):
 				signal = 0.0
 				signal = 0.0
-				incoming = allIncomingAssociationInstances(model, block, "Link")
-				while (read_nr_out(incoming) > 0):
-					selected = readAssociationSource(model, set_pop(incoming))
+				incoming = allAssociationOrigins(model, block, "FullRuntime/Link")
+				while (set_len(incoming) > 0):
+					selected = set_pop(incoming)
 					signal = signal + cast_float(read_attribute(model, selected, "signal"))
 					signal = signal + cast_float(read_attribute(model, selected, "signal"))
-			elif (blocktype == "MultiplyBlock"):
+			elif (blocktype == "FullRuntime/MultiplyBlock"):
 				signal = 1.0
 				signal = 1.0
-				incoming = allIncomingAssociationInstances(model, block, "Link")
-				while (read_nr_out(incoming) > 0):
-					selected = readAssociationSource(model, set_pop(incoming))
+				incoming = allAssociationOrigins(model, block, "FullRuntime/Link")
+				while (set_len(incoming) > 0):
+					selected = set_pop(incoming)
 					signal = signal * cast_float(read_attribute(model, selected, "signal"))
 					signal = signal * cast_float(read_attribute(model, selected, "signal"))
-			elif (blocktype == "NegatorBlock"):
-				incoming = allIncomingAssociationInstances(model, block, "Link")
+			elif (blocktype == "FullRuntime/NegatorBlock"):
 				signal = 0.0
 				signal = 0.0
-				while (read_nr_out(incoming) > 0):
-					selected = readAssociationSource(model, set_pop(incoming))
+				incoming = allAssociationOrigins(model, block, "FullRuntime/Link")
+				while (set_len(incoming) > 0):
+					selected = set_pop(incoming)
 					signal = float_neg(cast_float(read_attribute(model, selected, "signal")))
 					signal = float_neg(cast_float(read_attribute(model, selected, "signal")))
-			elif (blocktype == "InverseBlock"):
+			elif (blocktype == "FullRuntime/InverseBlock"):
 				signal = 0.0
 				signal = 0.0
-				incoming = allIncomingAssociationInstances(model, block, "Link")
-				while (read_nr_out(incoming) > 0):
-					selected = readAssociationSource(model, set_pop(incoming))
+				incoming = allAssociationOrigins(model, block, "FullRuntime/Link")
+				while (set_len(incoming) > 0):
+					selected = set_pop(incoming)
 					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 == "DelayBlock"):
+			elif (blocktype == "FullRuntime/DelayBlock"):
 				signal = 0.0
 				signal = 0.0
 				if (element_eq(read_attribute(model, block, "last_in"), read_root())):
 				if (element_eq(read_attribute(model, block, "last_in"), read_root())):
 					// No memory yet, so use initial condition
 					// No memory yet, so use initial condition
-					incoming = allIncomingAssociationInstances(model, block, "InitialCondition")
-					while (read_nr_out(incoming) > 0):
-						selected = readAssociationSource(model, set_pop(incoming))
+					incoming = allAssociationOrigins(model, block, "FullRuntime/InitialCondition")
+					while (set_len(incoming) > 0):
+						selected = set_pop(incoming)
 						signal = cast_float(read_attribute(model, selected, "signal"))
 						signal = cast_float(read_attribute(model, selected, "signal"))
 				else:
 				else:
 					signal = read_attribute(model, block, "last_in")
 					signal = read_attribute(model, block, "last_in")
-					unset_attribute(model, block, "last_in")
 				set_add(memory_blocks, block)
 				set_add(memory_blocks, block)
-			elif (blocktype == "IntegratorBlock"):
+			elif (blocktype == "FullRuntime/IntegratorBlock"):
 				if (element_eq(read_attribute(model, block, "last_in"), read_root())):
 				if (element_eq(read_attribute(model, block, "last_in"), read_root())):
 					// No history yet, so use initial values
 					// No history yet, so use initial values
-					incoming = allIncomingAssociationInstances(model, block, "InitialCondition")
-					while (read_nr_out(incoming) > 0):
-						selected = readAssociationSource(model, set_pop(incoming))
+					incoming = allAssociationOrigins(model, block, "FullRuntime/InitialCondition")
+					while (set_len(incoming) > 0):
+						selected = set_pop(incoming)
 						signal = cast_float(read_attribute(model, selected, "signal"))
 						signal = cast_float(read_attribute(model, selected, "signal"))
 				else:
 				else:
-					signal = cast_float(read_attribute(model, block, "last_in")) + (delta_t * cast_float(read_attribute(model, block, "last_out")))
-					unset_attribute(model, block, "last_in")
-					unset_attribute(model, block, "last_out")
+					signal = cast_float(read_attribute(model, block, "last_out")) + (delta_t * cast_float(read_attribute(model, block, "last_in")))
 				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 == "DerivatorBlock"):
+			elif (blocktype == "FullRuntime/DerivatorBlock"):
 				if (element_eq(read_attribute(model, block, "last_in"), read_root())):
 				if (element_eq(read_attribute(model, block, "last_in"), read_root())):
 					// No history yet, so use initial values
 					// No history yet, so use initial values
-					incoming = allIncomingAssociationInstances(model, block, "InitialCondition")
-					while (read_nr_out(incoming) > 0):
-						selected = readAssociationSource(model, set_pop(incoming))
+					incoming = allAssociationOrigins(model, block, "FullRuntime/InitialCondition")
+					while (set_len(incoming) > 0):
+						selected = set_pop(incoming)
 						signal = cast_float(read_attribute(model, selected, "signal"))
 						signal = cast_float(read_attribute(model, selected, "signal"))
 				else:
 				else:
-					incoming = allIncomingAssociationInstances(model, block, "Link")
-					while (read_nr_out(incoming) > 0):
-						selected = readAssociationSource(model, set_pop(incoming))
+					incoming = allAssociationOrigins(model, block, "FullRuntime/Link")
+					while (set_len(incoming) > 0):
+						selected = set_pop(incoming)
 						signal = (cast_float(read_attribute(model, selected, "signal")) - cast_float(read_attribute(model, block, "last_in"))) / delta_t
 						signal = (cast_float(read_attribute(model, selected, "signal")) - cast_float(read_attribute(model, block, "last_in"))) / delta_t
-					unset_attribute(model, block, "last_in")
 				set_add(memory_blocks, block)
 				set_add(memory_blocks, block)
-			elif (blocktype == "ProbeBlock"):
-				incoming = allIncomingAssociationInstances(model, block, "Link")
-				while (read_nr_out(incoming) > 0):
-					selected = readAssociationSource(model, set_pop(incoming))
-					signal = cast_float(read_attribute(model, selected, "signal"))
-					output((("SIM_PROBE " + cast_string(read_attribute(model, block, "name"))) + " ") + cast_string(signal))
-
-			unset_attribute(model, block, "signal")
+			elif (blocktype == "FullRuntime/ProbeBlock"):
+				incoming = allAssociationOrigins(model, block, "FullRuntime/Link")
+				while (set_len(incoming) > 0):
+					signal = cast_float(read_attribute(model, set_pop(incoming), "signal"))
+					output(cast_string(time) + " " + cast_string(read_attribute(model, block, "name")) + " " + cast_string(signal))
+
 			instantiate_attribute(model, block, "signal", signal)
 			instantiate_attribute(model, block, "signal", signal)
-	output("SIM_END")
 	
 	
-	while (read_nr_out(memory_blocks) > 0):
+	while (set_len(memory_blocks) > 0):
 		block = set_pop(memory_blocks)
 		block = set_pop(memory_blocks)
 		// Update memory
 		// Update memory
-		incoming = allIncomingAssociationInstances(model, block, "Link")
-		while (read_nr_out(incoming) > 0):
+		incoming = allIncomingAssociationInstances(model, block, "FullRuntime/Link")
+		while (set_len(incoming) > 0):
 			selected = readAssociationSource(model, set_pop(incoming))
 			selected = readAssociationSource(model, set_pop(incoming))
 			instantiate_attribute(model, block, "last_in", cast_float(read_attribute(model, selected, "signal")))
 			instantiate_attribute(model, block, "last_in", cast_float(read_attribute(model, selected, "signal")))
 
 
 	// Increase simulation time
 	// Increase simulation time
-	Float new_time
-	new_time = cast_float(read_attribute(model, time, "current_time")) + delta_t
-	unset_attribute(model, time, "current_time")
-	instantiate_attribute(model, time, "current_time", new_time)
-
-	return !
+	return time + delta_t!
 
 
 Void function eliminateGaussJordan(m : Element):
 Void function eliminateGaussJordan(m : Element):
 	Integer i
 	Integer i

+ 6 - 1
models/cbd_spring.mvc

@@ -39,11 +39,16 @@ Link (int1, m0) {}
 Link (cte_g, m1) {}
 Link (cte_g, m1) {}
 Link (cte_m, m1) {}
 Link (cte_m, m1) {}
 Link (cte_m, i0) {}
 Link (cte_m, i0) {}
-Link (m0, a0) {}
+Link (m0, n0) {}
 Link (n0, a0) {}
 Link (n0, a0) {}
+Link (m1, a0) {}
 Link (i0, m2) {}
 Link (i0, m2) {}
 Link (a0, m2) {}
 Link (a0, m2) {}
 Link (m2, int0) {}
 Link (m2, int0) {}
 Link (int0, int1) {}
 Link (int0, int1) {}
+
 InitialCondition (cte_v0, int0) {}
 InitialCondition (cte_v0, int0) {}
 InitialCondition (cte_y0, int1) {}
 InitialCondition (cte_y0, int1) {}
+
+Link (int0, pv) {}
+Link (int1, py) {}

+ 15 - 4
models/cbd_toRuntime.alc

@@ -3,10 +3,17 @@ include "modelling.alh"
 include "object_operations.alh"
 include "object_operations.alh"
 
 
 String function map_D2P(model : Element, name : String):
 String function map_D2P(model : Element, name : String):
-	log("Mapping element to Partial")
-	Element elems
-	elems = allAssociationDestinations(model, name, "D2P_block")
-	return set_pop(elems)!
+	Element destinations
+	String pick
+
+	destinations = allAssociationDestinations(model, name, "D2P_block")
+	log("Got destinations: " + set_to_string(destinations))
+
+	pick = name
+	while (pick == name):
+		pick = set_pop(destinations)
+
+	return pick!
 
 
 Boolean function main(model : Element):
 Boolean function main(model : Element):
 	Element all_blocks
 	Element all_blocks
@@ -24,6 +31,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)
 
 
 		// 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)
@@ -53,6 +61,9 @@ 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):

+ 2 - 1
models/pm_live_CBD.mvc

@@ -48,7 +48,8 @@ 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, fork1) {}
+Next (merge_0, simulate) {}
+
 Next (fork1, edit) {}
 Next (fork1, edit) {}
 Next (fork1, simulate) {}
 Next (fork1, simulate) {}
 Next (edit, toRuntime) {}
 Next (edit, toRuntime) {}

+ 3 - 3
wrappers/modelverse.py

@@ -55,8 +55,7 @@ def _next_ID():
 def __run_new_modelverse(address, username, password, callback, model):
 def __run_new_modelverse(address, username, password, callback, model):
     init(address)
     init(address)
     login(username, password)
     login(username, password)
-    if callback is not None:
-        callback(model)
+    callback(model)
     exit_save(model)
     exit_save(model)
 
 
 def __run_new_modelverse_activity(address, username, password, taskname, pipe, callback):
 def __run_new_modelverse_activity(address, username, password, taskname, pipe, callback):
@@ -67,7 +66,8 @@ def __run_new_modelverse_activity(address, username, password, taskname, pipe, c
 
 
     if t == "OP":
     if t == "OP":
         model = OUTPUT()
         model = OUTPUT()
-        __invoke(callback, model)
+        if callback is not None:
+            __invoke(callback, model)
         controller.addInput(Event("data_input", "action_in", [None, None]))
         controller.addInput(Event("data_input", "action_in", [None, None]))
         time.sleep(2)
         time.sleep(2)
     elif t == "SC":
     elif t == "SC":

+ 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 08:33:01 2017
+Date:   Thu Nov 16 13:02:20 2017
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server