|
@@ -35,6 +35,7 @@ Element function translate_to_runtime(design_model : Element):
|
|
|
String attribute
|
|
|
String src
|
|
|
String dst
|
|
|
+ String time
|
|
|
Element all_attributes
|
|
|
|
|
|
log("Translating to runtime model!")
|
|
@@ -48,6 +49,7 @@ Element function translate_to_runtime(design_model : Element):
|
|
|
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)
|
|
|
+ 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)
|
|
@@ -82,6 +84,11 @@ Element function translate_to_runtime(design_model : Element):
|
|
|
|
|
|
log("Solving loops (TODO)")
|
|
|
|
|
|
+ log("Creating simulation time")
|
|
|
+ time = instantiate_node(runtime_model, "Time", "time")
|
|
|
+ instantiate_attribute(runtime_model, time, "current_time", 0)
|
|
|
+ instantiate_attribute(runtime_model, time, "termination_time", 100)
|
|
|
+
|
|
|
log("DONE!")
|
|
|
return runtime_model!
|
|
|
|
|
@@ -184,29 +191,101 @@ Void function list_CBD(model : Element):
|
|
|
|
|
|
return !
|
|
|
|
|
|
-Void function start(model : Element):
|
|
|
- // Do a simulation loop, until we receive pause
|
|
|
+Void function step_simulation(model : Element):
|
|
|
+ String time
|
|
|
+ String schedule
|
|
|
+ Float value
|
|
|
+ Element incoming
|
|
|
+ String selected
|
|
|
+
|
|
|
+ time = "time"
|
|
|
+ if (readAttribute(model, time, "current_time") == 0):
|
|
|
+ schedule = "schedule_init"
|
|
|
+ else:
|
|
|
+ schedule = "schedule_run"
|
|
|
+
|
|
|
+ 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")))
|
|
|
+
|
|
|
+ // Execute "block"
|
|
|
+ blocktype = readType(model, block)
|
|
|
+ if (blocktype == "ConstantBlock"):
|
|
|
+ unset_attribute(model, block, "signal")
|
|
|
+ instantiate_attribute(model, block, "signal", read_attribute(model, block, "value"))
|
|
|
+ elif (blocktype == "AdditionBlock"):
|
|
|
+ unset_attribute(model, block, "signal")
|
|
|
+ value = 0.0
|
|
|
+ incoming = allIncomingAssociationInstances(model, schedule, "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)
|
|
|
+
|
|
|
+ // Increase simulation time
|
|
|
+ Integer new_time
|
|
|
+ new_time = cast_v2i(read_attribute(model, time, "current_time")) + 1
|
|
|
+ unset_attribute(model, time, "current_time")
|
|
|
+ instantiate_attribute(model, time, "current_time", new_time)
|
|
|
+
|
|
|
+ return !
|
|
|
+
|
|
|
+Void function set_termination_time(model : Element):
|
|
|
+ unset_attribute(model, "time", "termination_time")
|
|
|
+ instantiate_attribute(model, "time", "termination_time", input())
|
|
|
+ return !
|
|
|
|
|
|
Void function execute_cbd(model : Element):
|
|
|
model = translate_to_runtime(model)
|
|
|
|
|
|
String cmd
|
|
|
+ Boolean running
|
|
|
+ running = False
|
|
|
+
|
|
|
while (True):
|
|
|
output("Which operation do you want to execute?")
|
|
|
- cmd = input()
|
|
|
+ if (running):
|
|
|
+ if (has_input()):
|
|
|
+ cmd = input()
|
|
|
+ else:
|
|
|
+ cmd = "start"
|
|
|
+ else:
|
|
|
+ cmd = input()
|
|
|
|
|
|
if (cmd == "help"):
|
|
|
output("Supported operations:")
|
|
|
- output(" start -- start simulation")
|
|
|
- output(" pause -- pause simulation")
|
|
|
- output(" modify -- live modelling: modify model structure")
|
|
|
- output(" list -- list blocks and connections")
|
|
|
+ if (bool_not(running)):
|
|
|
+ output(" step -- do one simulation step")
|
|
|
+ output(" start -- start simulation")
|
|
|
+ //output(" modify -- live modelling: modify model structure")
|
|
|
+ output(" list -- list blocks and connections")
|
|
|
+ output(" exit -- select another model")
|
|
|
+ else:
|
|
|
+ output(" pause -- pause simulation")
|
|
|
output(" help -- this information")
|
|
|
- output(" exit -- select another model")
|
|
|
- elif (cmd == "list"):
|
|
|
- list_CBD(model)
|
|
|
- elif (cmd == "exit"):
|
|
|
- return!
|
|
|
+ output(" term -- set termination time")
|
|
|
+ elif (cmd == "step"):
|
|
|
+ // Do a simulation step
|
|
|
+ step_simulation(model)
|
|
|
+ elif (cmd == "term"):
|
|
|
+ set_termination_time(model)
|
|
|
+ elif (running):
|
|
|
+ if (cmd == "pause"):
|
|
|
+ running = False
|
|
|
+ else:
|
|
|
+ output("Did not understand command!")
|
|
|
+ output("Use 'help' for a list of available options")
|
|
|
else:
|
|
|
- output("Did not understand command!")
|
|
|
- output("Use 'help' for a list of available options")
|
|
|
+ // Not running
|
|
|
+ if (cmd == "list"):
|
|
|
+ list_CBD(model)
|
|
|
+ elif (cmd == "start"):
|
|
|
+ running = True
|
|
|
+ elif (cmd == "exit"):
|
|
|
+ return!
|
|
|
+ else:
|
|
|
+ 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"))):
|
|
|
+ running = False
|