Getting started with Simulation of Urban Mobility (SUMO)
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.
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.
That’s it! Now let’s get to creating your first simulation of traffic flow on a network!
Simulating traffic in grid 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
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.
Generate the Routes
Next, we generate the routes taken by individual vehicles using SUMO’s jtrrouter , between times 0 to 10000.
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.
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.
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.
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).