# Getting started with Simulation of Urban Mobility (SUMO)

Contents

## Introduction

The Simulation of Urban Mobility (SUMO) platform is an open source platform that enables simulation of traffic flows in complex environments. There aren’t many tutorials I’ve come across that teach you how to create a complex traffic simulation from start to finish.

## Installation

There are multiple ways to install SUMO , but I prefer the pip install way, that installs SUMO as well as the python libraries to interface with SUMO.

 1 2 3 4 5 6 7  conda create -n SUMO conda activate SUMO pip install eclipse-sumo pip install traci pip install pytz pip install pandas pip install openpyxl 

That’s it! Now let’s get to creating your first simulation of traffic flow on a network!

## Generate Map/networks

In urban planning, grid road networks are pretty common. In SUMO, we setup a 5x5 grid with each road of length 200m, and 3 lanes, as below: netgenerate document

 1  netgenerate --grid true --grid.number=5 -L=3 --grid.length=200 --output-file=grid.net.xml 

## Generate Random Trip/Flow

Next, we use randomTrips.py located in the tools folder within the SUMO home directory (sumo -> tools), to generate random trips for a certain number of vehicles (200 vehicles in the example below). The begin and end times denote the times during which the vehicles enter the simulation. I’ve chosen 0&1, meaning all vehicles enter the simulation in the first 1 second of the simulation. Period denotes the arrival rate of vehicles.

 1  ../sumo/tools/randomTrips.py -n grid.net.xml -o flows.xml -b 0 -e 1 -p 1 --flows 200 

## Generate the Routes

Next, we generate the routes taken by individual vehicles using SUMO’s jtrrouter , between times 0 to 10000.

 1  jtrrouter --route-files flows.xml --net-file grid.net.xml --output-file grid.rou.xml --begin 0 --end 100 --accept-all-destinations true 

Finally, for simplicity we want to maintain a constant density. The most obvious way to do this is by vehicles driving randomly, and not exiting the simulation. For this, we use the Manhattan traffic model, where vehicles encountering an intersection choose to either go straight, left, or right based on set probabilities. By default in SUMO, vehicles exit the simulation once they reach their destination. However, SUMO has an implementation of the Manhattan model, using a continuous rerouter python script.

 1  ../sumo/tools/generateContinuousRerouters.py -n grid.net.xml --end 100 -o rerouter.add.xml 

## SUMO configuration file

Next, we create a sumo config file, in order to run the simulation in SUMO, which is basically a .xml file with certain attributes, containing the names of the network file, route file, and additional rerouting file for vehicles to stay in the simulation until the simulation is completed. We define an output file: grid.sumocfg, to store the detailed vehicle information during the traffic simulation.

 1  nvim grid.sumocfg 
  1 2 3 4 5 6 7 8 9 10 11 12 13 14   

Finally, we run the simulation in the terminal as below. Period denotes the time interval at which data is saved — 100 denotes saving vehicular information i.e. speed and position, every 100 timesteps.

sumo-gui document.

 1  sumo-gui -c ./grid.sumocfg --device.fcd.period 100 

Running this pops up the SUMO GUI, where you can see the entire simulation!

Vehicle colors indicate their speeds from slowest (red) to fastest (green).