Forráskód Böngészése

Fixed CBD simulation semantics: stepping seems to work in basic
situations

Yentl Van Tendeloo 8 éve
szülő
commit
39263f286a

+ 0 - 4
integration/code/cbd_runtime.mvc

@@ -74,10 +74,6 @@ SCD CausalBlockDiagrams_Runtime{
 
     Class Schedule {
         lower_cardinality = 1
-        active : Boolean {
-            target_lower_cardinality = 1
-            target_upper_cardinality = 1
-        }
     }
 
     Association LinkedBlock(Schedule, Block){

+ 25 - 23
integration/code/cbd_semantics.alc

@@ -48,13 +48,12 @@ Element function translate_to_runtime(design_model : Element):
 	while (list_len(all_blocks) > 0):
 		element_name = set_pop(all_blocks)
 		mm_type_name = reverseKeyLookup(design_model["metamodel"]["model"], dict_read_node(design_model["type_mapping"], design_model["model"][element_name]))
-		instantiate_node(runtime_model, mm_type_name, element_name)
+		element_name = instantiate_node(runtime_model, mm_type_name, element_name)
+		if (mm_type_name == "ConstantBlock"):
+			instantiate_attribute(runtime_model, element_name, "value", read_attribute(design_model, element_name, "value"))
+		elif (mm_type_name == "DelayBlock"):
+			instantiate_attribute(runtime_model, element_name, "memory", 0.0)
 		instantiate_attribute(runtime_model, element_name, "signal", 0.0)
-		all_attributes = getAttributeList(design_model, element_name)
-		while (read_nr_out(all_attributes) > 0):
-			attr_name = set_pop(all_attributes)
-			if (bool_not(set_in(runtime_model["model"], read_attribute(design_model, element_name, attr_name)))):
-				instantiate_attribute(runtime_model, element_name, attr_name, read_attribute(design_model, element_name, attr_name))
 		log("    Converted block " + element_name)
 
 	// Don't merge this together with the block conversion, as the destination block might not exist yet!
@@ -111,7 +110,6 @@ Void function create_schedule(model : Element, is_time_zero : Boolean):
 		schedule = instantiate_node(model, "Schedule", "schedule_init")
 	else:
 		schedule = instantiate_node(model, "Schedule", "schedule_run")
-	instantiate_attribute(model, schedule, "active", True)
 
 	while (read_nr_out(all_blocks) > 0):
 		element_name = set_pop(all_blocks)
@@ -138,7 +136,6 @@ Void function create_schedule(model : Element, is_time_zero : Boolean):
 
 			if (ready):
 				new_schedule = instantiate_node(model, "Schedule", "")
-				instantiate_attribute(model, new_schedule, "active", False)
 				instantiate_link(model, "LinkedBlock", "", schedule, element_name)
 				instantiate_link(model, "NextSchedule", "", schedule, new_schedule)
 				schedule = new_schedule
@@ -175,7 +172,6 @@ Void function list_CBD(model : Element):
 
 	output("Schedule (== 0):")
 	elem = "schedule_init"
-	log("Model " + cast_e2s(model["model"][elem]))
 	while (read_nr_out(allOutgoingAssociationInstances(model, elem, "LinkedBlock")) > 0):
 		block = readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, elem, "LinkedBlock")))
 		output("    " + block)
@@ -183,7 +179,6 @@ Void function list_CBD(model : Element):
 
 	output("Schedule (> 0):")
 	elem = "schedule_run"
-	log("Model " + cast_e2s(model["model"][elem]))
 	while (read_nr_out(allOutgoingAssociationInstances(model, elem, "LinkedBlock")) > 0):
 		block = readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, elem, "LinkedBlock")))
 		output("    " + block)
@@ -194,39 +189,46 @@ Void function list_CBD(model : Element):
 Void function step_simulation(model : Element):
 	String time
 	String schedule
-	Float value
+	Float signal
 	Element incoming
 	String selected
+	String block
+	String elem
+	String blocktype
 
 	time = "time"
-	if (readAttribute(model, time, "current_time") == 0):
+	if (cast_s2i(cast_v2s(read_attribute(model, time, "current_time"))) == 0):
 		schedule = "schedule_init"
 	else:
 		schedule = "schedule_run"
 
+	output("==== START ====")
 	while (read_nr_out(allOutgoingAssociationInstances(model, schedule, "LinkedBlock")) > 0):
-		block = readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, elem, "LinkedBlock")))
-		schedule = readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, elem, "NextSchedule")))
+		block = readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, schedule, "LinkedBlock")))
+		schedule = readAssociationDestination(model, set_pop(allOutgoingAssociationInstances(model, schedule, "NextSchedule")))
 
 		// Execute "block"
 		blocktype = readType(model, block)
+		unset_attribute(model, block, "signal")
 		if (blocktype == "ConstantBlock"):
-			unset_attribute(model, block, "signal")
-			instantiate_attribute(model, block, "signal", read_attribute(model, block, "value"))
+			signal = read_attribute(model, block, "value")
+			log("Value: " + cast_v2s(read_attribute(model, block, "value")))
 		elif (blocktype == "AdditionBlock"):
-			unset_attribute(model, block, "signal")
-			value = 0.0
-			incoming = allIncomingAssociationInstances(model, schedule, "Link")
+			signal = 0.0
+			incoming = allIncomingAssociationInstances(model, block, "Link")
 			while (read_nr_out(incoming) > 0):
 				selected = readAssociationSource(model, set_pop(incoming))
-				value = value + cast_v2f(read_attribute(model, selected, "signal"))
-			instantiate_attribute(model, block, "signal", value)
+				log("V += " + cast_v2s(read_attribute(model, selected, "signal")))
+				signal = signal + cast_s2f(cast_v2s(read_attribute(model, selected, "signal")))
+		instantiate_attribute(model, block, "signal", signal)
+		output((("    " + block) + " = ") + cast_v2s(read_attribute(model, block, "signal")))
 
 	// Increase simulation time
 	Integer new_time
-	new_time = cast_v2i(read_attribute(model, time, "current_time")) + 1
+	new_time = cast_s2i(cast_v2s(read_attribute(model, time, "current_time"))) + 1
 	unset_attribute(model, time, "current_time")
 	instantiate_attribute(model, time, "current_time", new_time)
+	output("====  END  ====")
 
 	return !
 
@@ -287,5 +289,5 @@ Void function execute_cbd(model : Element):
 				output("Did not understand command!")
 				output("Use 'help' for a list of available options")
 
-		if (cast_v2i(read_attribute(model, "time", "current_time")) > cast_v2i(read_attribute(model, "time", "termination_time"))):
+		if (cast_s2i(cast_v2s(read_attribute(model, "time", "current_time"))) > cast_s2i(cast_v2s(read_attribute(model, "time", "termination_time")))):
 			running = False

+ 1 - 0
interface/HUTN/includes/primitives.alh

@@ -92,3 +92,4 @@ Boolean function has_value(a : Element)
 
 Element function exec(a : Element)
 Element function resolve(var_name : String)
+Boolean function has_input()