Basic simulators

In order to test custom-made simulators, two basic simulators are provided to use and connect to.

  • The InputSimulator is 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 OutputSimulator writes data from a custom simulator into a python dictionary. Users can access this dictionary by calling get_dict on 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))