|
@@ -7,8 +7,6 @@ include "io.alh"
|
|
|
include "typing.alh"
|
|
include "typing.alh"
|
|
|
|
|
|
|
|
Boolean function main(model : Element):
|
|
Boolean function main(model : Element):
|
|
|
- log("Translating DEVS to string representation!")
|
|
|
|
|
-
|
|
|
|
|
String model_rep
|
|
String model_rep
|
|
|
Element all_atomics
|
|
Element all_atomics
|
|
|
Element curr_atomic
|
|
Element curr_atomic
|
|
@@ -29,13 +27,13 @@ Boolean function main(model : Element):
|
|
|
String curr_submodel_type
|
|
String curr_submodel_type
|
|
|
String curr_submodel_parameters
|
|
String curr_submodel_parameters
|
|
|
|
|
|
|
|
- model_rep = "\nfrom DEVS import *\nfrom infinity import INFINITY\n\n"
|
|
|
|
|
|
|
+ model_rep = ""
|
|
|
|
|
|
|
|
all_atomics = allInstances(model, "DEVS/AtomicDEVSBlock")
|
|
all_atomics = allInstances(model, "DEVS/AtomicDEVSBlock")
|
|
|
while (read_nr_out(all_atomics) > 0):
|
|
while (read_nr_out(all_atomics) > 0):
|
|
|
curr_atomic = set_pop(all_atomics)
|
|
curr_atomic = set_pop(all_atomics)
|
|
|
model_rep = model_rep + "class " + cast_string(read_attribute(model, curr_atomic, "name")) + "(AtomicDEVS):\n"
|
|
model_rep = model_rep + "class " + cast_string(read_attribute(model, curr_atomic, "name")) + "(AtomicDEVS):\n"
|
|
|
- model_rep = model_rep + "\tdef __init__(self, name=" + cast_value(read_attribute(model, curr_atomic, "name")) + ", parameters):\n"
|
|
|
|
|
|
|
+ model_rep = model_rep + "\tdef __init__(self, name, parameters):\n"
|
|
|
model_rep = model_rep + "\t\tself.parameters = parameters\n"
|
|
model_rep = model_rep + "\t\tself.parameters = parameters\n"
|
|
|
model_rep = model_rep + "\t\tAtomicDEVS.__init__(self, name)\n"
|
|
model_rep = model_rep + "\t\tAtomicDEVS.__init__(self, name)\n"
|
|
|
model_rep = model_rep + "\t\tself.initialState()\n"
|
|
model_rep = model_rep + "\t\tself.initialState()\n"
|
|
@@ -62,7 +60,7 @@ Boolean function main(model : Element):
|
|
|
while (read_nr_out(all_coupleds) > 0):
|
|
while (read_nr_out(all_coupleds) > 0):
|
|
|
curr_coupled = set_pop(all_coupleds)
|
|
curr_coupled = set_pop(all_coupleds)
|
|
|
model_rep = model_rep + "class " + cast_string(read_attribute(model, curr_coupled, "name")) + "(CoupledDEVS):\n"
|
|
model_rep = model_rep + "class " + cast_string(read_attribute(model, curr_coupled, "name")) + "(CoupledDEVS):\n"
|
|
|
- model_rep = model_rep + "\tdef __init__(self, name=" + cast_value(read_attribute(model, curr_coupled, "name")) + "):\n"
|
|
|
|
|
|
|
+ model_rep = model_rep + "\tdef __init__(self, name, parameters):\n"
|
|
|
model_rep = model_rep + "\t\tCoupledDEVS.__init__(self, name)\n"
|
|
model_rep = model_rep + "\t\tCoupledDEVS.__init__(self, name)\n"
|
|
|
model_rep = model_rep + "\t\tself.my_ports = {"
|
|
model_rep = model_rep + "\t\tself.my_ports = {"
|
|
|
all_ports = allAssociationDestinations(model, curr_coupled, "DEVS/DEVSBlockToPort")
|
|
all_ports = allAssociationDestinations(model, curr_coupled, "DEVS/DEVSBlockToPort")
|
|
@@ -70,7 +68,6 @@ Boolean function main(model : Element):
|
|
|
curr_port = set_pop(all_ports)
|
|
curr_port = set_pop(all_ports)
|
|
|
curr_port_name = cast_value(read_attribute(model, curr_port, "name"))
|
|
curr_port_name = cast_value(read_attribute(model, curr_port, "name"))
|
|
|
curr_port_type = read_type(model, curr_port)
|
|
curr_port_type = read_type(model, curr_port)
|
|
|
- log(curr_port_type)
|
|
|
|
|
if (curr_port_type == "DEVS/InputPort"):
|
|
if (curr_port_type == "DEVS/InputPort"):
|
|
|
model_rep = model_rep + curr_port_name + ": self.addInPort(" + curr_port_name + ")"
|
|
model_rep = model_rep + curr_port_name + ": self.addInPort(" + curr_port_name + ")"
|
|
|
if (curr_port_type == "DEVS/OutputPort"):
|
|
if (curr_port_type == "DEVS/OutputPort"):
|
|
@@ -101,12 +98,10 @@ Boolean function main(model : Element):
|
|
|
while (read_nr_out(all_submodels) > 0):
|
|
while (read_nr_out(all_submodels) > 0):
|
|
|
curr_submodel = set_pop(all_submodels)
|
|
curr_submodel = set_pop(all_submodels)
|
|
|
curr_submodel_name = cast_value(read_attribute(model, curr_submodel, "name"))
|
|
curr_submodel_name = cast_value(read_attribute(model, curr_submodel, "name"))
|
|
|
- log(curr_submodel_name)
|
|
|
|
|
all_ports = allAssociationDestinations(model, curr_submodel, "DEVS/DEVSInstanceToPort")
|
|
all_ports = allAssociationDestinations(model, curr_submodel, "DEVS/DEVSInstanceToPort")
|
|
|
while (read_nr_out(all_ports) > 0):
|
|
while (read_nr_out(all_ports) > 0):
|
|
|
curr_port = set_pop(all_ports)
|
|
curr_port = set_pop(all_ports)
|
|
|
out_channels = allAssociationDestinations(model, curr_port, "DEVS/Channel")
|
|
out_channels = allAssociationDestinations(model, curr_port, "DEVS/Channel")
|
|
|
- log(cast_value(read_nr_out(out_channels)))
|
|
|
|
|
while (read_nr_out(out_channels) > 0):
|
|
while (read_nr_out(out_channels) > 0):
|
|
|
curr_channel = set_pop(out_channels)
|
|
curr_channel = set_pop(out_channels)
|
|
|
possible_parent = allAssociationOrigins(model, curr_channel, "DEVS/DEVSInstanceToPort")
|
|
possible_parent = allAssociationOrigins(model, curr_channel, "DEVS/DEVSInstanceToPort")
|
|
@@ -125,16 +120,12 @@ Boolean function main(model : Element):
|
|
|
String devs_model
|
|
String devs_model
|
|
|
port = comm_connect("pypdevs_simulator")
|
|
port = comm_connect("pypdevs_simulator")
|
|
|
|
|
|
|
|
- log("(PDEVS) task name = " + get_taskname())
|
|
|
|
|
- log("(PDEVS) Sending model...")
|
|
|
|
|
comm_set(port, model_rep)
|
|
comm_set(port, model_rep)
|
|
|
- log("(PDEVS) " + port)
|
|
|
|
|
|
|
|
|
|
comm_set(port, "[\"simulate\"]")
|
|
comm_set(port, "[\"simulate\"]")
|
|
|
|
|
|
|
|
while (True):
|
|
while (True):
|
|
|
if (comm_hasInput(port)):
|
|
if (comm_hasInput(port)):
|
|
|
- log(cast_value(has_input()))
|
|
|
|
|
the_input = comm_get(port)
|
|
the_input = comm_get(port)
|
|
|
log("(PDEVS) Got input from simulator!")
|
|
log("(PDEVS) Got input from simulator!")
|
|
|
log("(PDEVS) " + the_input)
|
|
log("(PDEVS) " + the_input)
|