Basic simulators¶
In order to test custom-made simulators, two basic simulators are provided to use and connect to.
The
InputSimulatoris a simulator that can be used to feed either a constant value or the value of a function into a designated simulator ready to handle the data.The
OutputSimulatorwrites data from a custom simulator into a python dictionary. Users can access this dictionary by callingget_dicton a created output simulator entity.
Below is an example code snippet that connects the input simulator with the output simulator and executes ten time steps. After the simulation is done, the dictionary including the values received by the input simulator is printed.
# The output simulator is initialized.
output_dict = world.start("OutputSim")
# Two entities of the output simulator model are created.
output_model = output_dict.Dict.create(2)
# The input simulator is initialized.
input = world.start("InputSim", step_size=1)
# One function input simulator entity is created.
input_model_func = input.Function.create(1, function=sample_function)
# One constant input simulator entity is created.
input_model_const = input.Constant.create(1, constant=2)
# The input entities are connected to separate output entities
world.connect(input_model_func[0], output_model[1], "value")
world.connect(input_model_const[0], output_model[0], "value")
# Run simulation.
world.run(until=END)
# Dictionary content is printed.
pprint(output_dict.get_dict(output_model[0].eid))
pprint(output_dict.get_dict(output_model[1].eid))