Running a simulation in Symupy

In order to run a simulation you need two main elements:

  • A symuflow library. Although it is already within the dependencies you may retrieve the simulator via the conda package conda install -c licit-lab symuflow. This will obtain the traffic simulator library.

  • An XML file with an scenario

[1]:
from symupy.runtime.api import Simulator, Simulation
import os

bottleneck = os.path.abspath("bottleneck_001.xml")
Successful import of symupy
/home/docs/checkouts/readthedocs.org/user_builds/symupy/conda/stable/lib/python3.9/site-packages/conda/utils/lib
Default path: /home/docs/checkouts/readthedocs.org/user_builds/symupy/conda/stable/lib/libSymuFlow.so

First create a Simulator object, the simulator object is in charge of establishing a comunication with Symuflow

[2]:
s = Simulator()
Configurator: Initialization
Using default defined library path
Runtime: Initialization

Attach the simulation file to a simulator

[3]:
s.register_simulation(bottleneck)

Launch your simulation

[4]:
s.run()
run_simulation ran in: 0.14736151695251465 sec

Run step by step

You may interact with the simulation by running a simulation step by step

[5]:
s = Simulator()
s.register_simulation(bottleneck)
with s:
    while s.do_next:
        s.run_step()
Configurator: Initialization
Using default defined library path
Runtime: Initialization
Step: 0
Step: 1
Step: 2
Step: 3
Step: 4
Step: 5
Step: 6
Step: 7
Step: 8
Step: 9
Step: 10
Step: 11
Step: 12
Step: 13
Step: 14
Step: 15
Step: 16
Step: 17
Step: 18
Step: 19
Step: 20
Step: 21
Step: 22
Step: 23
Step: 24
Step: 25
Step: 26
Step: 27
Step: 28
Step: 29
Runtime: End

End of tutorial.