Tutorials/Hello Sumo
This tutorial assumes very basic computer skill. If you run into any questions please read the page Basics/Basic Computer Skills.
Contents |
Hello Sumo - Introduction
This tutorial aims at first time Sumo users. We are building the simplest net possible and let a single car drive on it. All files mentioned here can also be found in the <SUMO_HOME>/docs/tutorial/hello directory. The most recent version can be found in the SVN at <SUMO_HOME>/tests/complex/tutorial/hello/data/.
In SUMO a street network consists of nodes (junctions) and edges (streets connecting the junctions). Thus, if we want to create a network with two streets, subsequent to each other, we need three nodes and two edges. We will see in the section on #Routes, why the simplest network cannot contain only one edge.
Nodes
All nodes have at location (x- and y-coordinate, describing distance to the origin in meters) and an id for future reference. Thus our simple node file looks as follows
<nodes>
<node id="1" x="-500.0" y="0.0" />
<node id="2" x="+500.0" y="0.0" />
<node id="3" x="+501.0" y="0.0" />
</nodes>
You can edit a file with a text editor of your choice and save this for instance as hello.nod.xml where .nod.xml is the default suffix for Sumo node files.
Edges
Now we are connecting the nodes with edges. This is as easy as it sounds. We have a source node id, a target node id, and an edge id for future reference. Edges are directed, thus every vehicle travelling this edge will start at the node given in from and end at the node given in to.
<edges>
<edge from="1" id="1to2" to="2" />
<edge from="2" id="out" to="3" />
</edges>
Save this data into a file called hello.edg.xml. Now that we have nodes and edges we can call the first SUMO tool to create a network. Make sure NETCONVERT is somewhere in your PATH and call
netconvert --node-files=hello.nod.xml --edge-files=hello.edg.xml --output-file=hello.net.xml
This will generate our network called hello.net.xml.
Routes
Now that we have a net, we still need a car. In SUMO the vehicles have types defining their basic properties such as length, acceleration and deceleration, and maximum speed. Furthermore it needs a so called sigma parameter which introduces some random behavior and is due to the car following model used. Setting it to 0 gives a deterministic car.
Now we define a route for our car which simply consists of the two edges we defined. The reason why we need two edges is that in SUMO the car disappears as soon as it has reached the last edge of its route (the position of a car is defined by the position of its front).
Please note, that SUMO now allows routes with only one edge, see "Definition of Vehicles, Vehicle Types, and Routes" for further information.
Last but not least we define our single car mainly referring to the entries before and giving it a departure time as in the following hello.rou.xml file.
<routes>
<vType accel="1.0" decel="5.0" id="Car" length="2.0" maxSpeed="100.0" sigma="0.0" />
<route id="route0" edges="1to2 out"/>
<vehicle depart="1" id="veh0" route="route0" type="Car" />
</routes>
Configuration
Now we glue everything together into a configuration file
<configuration>
<input>
<net-file value="hello.net.xml"/>
<route-files value="hello.rou.xml"/>
</input>
<time>
<begin value="0"/>
<end value="10000"/>
</time>
</configuration>
Saving this to hello.sumo.cfg we can start the simulation by either
sumo -c hello.sumocfg
or with GUI by
sumo-gui -c hello.sumocfg
Further Reading
More information on defining networks using XML can be found here: Networks/Building Networks from own XML-descriptions. NETCONVERT also allows to import networks from other applications, further information is available here: Networks/Import.
More information on defining vehicles can be found here: Definition of Vehicles, Vehicle Types, and Routes.