Skip to main content

Run Simulation

The simplest way to run a simulation by moss is as follows:

from moss import Engine

eng = Engine(
map_file="./data/map.pb",
agent_file="./data/trip.pb",
start_step=6 * 3600,
device=0,
)
for h in range(1):
eng.next_step(3600)
att = eng.get_departed_vehicle_average_traveling_time()
tp = eng.get_finished_vehicle_count()
print(f'{h} {att:.3f} {tp}')

The above code snippet creates an Engine object, which is the core class of moss. The Engine object is initialized with the following necessary parameters:

  • map_file: the path to the map protobuf file.
  • agent_file: the path to the agent protobuf file.
  • start_step: the start time of the simulation in seconds.
  • device: the GPU device index to run the simulation.

Note: more details about the Engine class can be found in the Python API.

The simulation is then run for one hour by calling the next_step method. You can choose the step number as you like. After next_step is called, you can use Engine API to get simulation results and metrics and do whatever you want like data analysis, visualization, etc.