This Tutorial is meant to serve as a high-level guide for building a sumo scenario. It provides an outline of the typical steps when building a scenario and lists the recommended wiki pages for each step.
Build the road network#
Every simulation requires a road network. The application netconvert is used to create a network which can be used by the simulation sumo. It is also possible to build/modify a simulation network by hand with use of netedit, which provides a graphical user interface.
If you already have some network data#
If you do not yet have any network data#
Generate the traffic#
First you should understand the basics of vehicle modelling: Definition_of_Vehicles,_Vehicle_Types,_and_Routes. You have various ways to insert vehicles into the map. Your choice basically depends on what kind of information about the traffic you have: Demand/Introduction_to_demand_modelling_in_SUMO.
Improve your Scenario#
Most methods for network import leave some aspect of deficient network quality. Very often this manifests as unexpected/unrealistic traffic jams and teleporting vehicle errors.
Modifying the Network#
You will have to patch your network data to add missing roads, prohibit some turns, correct the number of lanes and add/remove some traffic lights. The recommended ways to perform the necessary changes include:
- Encode the changes in plain-xml files as described in Networks/Building_Networks_from_own_XML-descriptions. Most XML-attributes are optional so you only need to set the values you would like to change.
- patch your network using netconvert by loading the net.xml along with the plain-xml files. You can even use this during the initial import (i.e. load an OSM-file along with your plain-xml files)
- directly adjust your network with GUI: after opening the program netedit you load the network file (*.net.xml)that needs to be modified. Then you choose the respective funtions in netedit to modify e.g. the number of lanes, road shapes, traffic signal plans, intersection geometries, and to combine intersections or edges.
Example: Patching the type of a node#
prepare a file like this:
<nodes> <node id="id_of_the_node_you_want_to_modify" type="right_before_left"/> <nodes>
and patch the network like this:
netconvert --sumo-net-file your.net.xml --node-files patch.nod.xml -o yourpatched.net.xml
or perform the patch during the initial import:
netconvert --osm-file yourOSMfile.xml --node-files patch.nod.xml ...<other options>
Modifying an imported network via plain.xml#
Instead of patching individual elements you can also convert your network to plain.xml and modify the plain file and then re-assemble the network like this:
netconvert --sumo-net-file your.net.xml --plain-output-prefix yourplain
or during import:
netconvert --osm-files yourOSMinput.xml --plain-output-prefix yourplain ... <your other options>
This will give you the files:
yourplain.edg.xml yourplain.nod.xml yourplain.con.xml yourplain.tll.xml
You can edit these files and then reassamble the network buy loading some or all of them:
netconvert --edge-files yourplain.edg.xml --node-files yourplain.nod.xml -o new.net.xml
netconvert --edge-files yourplain.edg.xml --node-files yourplain.nod.xml --connection-files yourplain.con.xml -o new.net.xml
When working with networks based on OSM input, the .edg.xml file will contain information on the OSM-type of an edge (i.e. highway.residential. When loading such an .edg.xml file with netconvert you need to supply the option --ignore-errors.edge-type or load a type-file to prevent errors of the form Type ... not defined.
Modifying node positions with the help of sumolib#
Sumolib is a python library for working with SUMO files. The file <SUMO_HOME>/tests/tools/sumolib/patch_network/runner.py provides an example for randomly changing all node positions with a few lines of python code.
Traffic Light Programs#
In almost all cases the traffic light programs will have been guessed by netconvert and turn out different from the real traffic lights. A simple way to improve traffic lights programs is making them start their program cycle at a different time. Experiment with the option --tls.half-offset and all the other --tls.* options of netconvert.
A more practical and efficient way to improve your traffic lights is to give the program explicitly with a tls.xml file.
At this time netconvert only supports the creation of static traffic light programs. For dynamic traffic lights see Tutorials/TraCI4Traffic_Lights. Furthermore, actuated traffic control can also be set, either based on time gaps or time loss. More information about actuated traffic control and settings can be found at Simulation/Traffic_Lights#Actuated_Traffic_Lights).
If you have two networks A.net.xml and B.net.xml you may wish to find out how they differ. This can be accomplished using the tool <SUMO_HOME>/tools/net/netdiff.py. Running this tool will give you a set of plain-XML difference files. They only contain the differences grouped by deleted, created and changed elements. It is even possible to load these files along with A.net.xml to recreate B.net.xml.