Hi everybody. In this video, we're going to learn about SUMO networks and how to
create a SUMO network by hand and also using net generate. We're also going to
learn how to create a simulation in sumo. So first what is a SUMO network? In sumo
a SUMO network file defines the traffic-related part of a map.
The SUMO network file defines the roads and intersections that simulated
vehicles run along or across. A SUMO network is basically a directed graph,
and like a directed graph the SUMO network consists of nodes or
vertices and edges. The nodes and vertices represent intersections that
are called junctions in SUMO and the edges represent the roads or streets and
they are unidirectional the SUMO network contains the following
information every street which is our edges are a collection of lanes and that
includes the position shape and speed limit on every lane there are traffic
lane logistics that are referenced within the junctions the junctions
include the rightaway regulations within them and connections between those lanes
and junctions these can be enhanced by user input formats and set processing
options so that they can include districts and roundabouts descriptions
now that we know what a SUMO network is let's create a SUMO network. This is the
network that we are going to create, it's a very simple Manhattan grid, this can be
done by hand or by using net generate so first let's learn how to create a sumo
network by hand. In order to create a network by hand we must first create a
node file the node file describes the junctions in SUMO. Node files normally
have the extension .nod.xml so let's make a node file and I'm gonna
make this in a folder called sumo tutorials so I'm gonna make a new file
and this will be sumotest.nod.xml that's its extension this is an
XML file and let's edit this file so we need to define the nodes for our network
so in this case we have a collection of nodes so in XML we start our attribute
with the nodes attribute saying that there is a collection of nodes and let's
close that collection of nodes now we need to define each node in our network
in this case I have our network that we are going to be creating down here and I
have our nodes labeled it's 1 2 3 4 5 6 all the way to 18 so when you're
defining a node you declare a game code and then you set the ID the ID is can be
a string in this case I'm gonna have our ID be this number so ID equals 1 that
list is representing the string 1 so you could call it intersection 1 if you want
it to the next parameter that we have is our X this is going to be a float so in
the case for 1 it is at 0 0 so it's at 0 x and 0 y so x is 0.0 and Y is 0.0
this is all that is required in sumo there are other optional parameters that
you can add for example you can have a type and we can set the type of our
intersection to different values in this case we can set it to priority the type
priority in SUMO means that vehicles that are on a low priority edge have to
wait until a vehicle on a higher priority edge has passed in the junction
there's other types that you can have such as traffic light right before left
unregulated and several more there are other types as well there's tlType
which denotes the traffic link algorithm and then there are radiuses
shapes rate right aways so there's lots of attributes that you can add to your
node right now we are just doing the type so we have 18 nodes so let's add
our second note so our second node it's going to have
the ID too and at its position it's down here so it's our entire length of our
SUMO map is 2 kilometers or 2,000 meters so our XY is done in meters so
our X is still 0 but our Y is now at negative 1000
so this is where node 2 is let's add node 3 so node 3 our X is still at 0 and our
Y as I had negative 2000 let's add the remainder of our nodes if you look here
this for our entire length of our map is 2.5 kilometres or 2500 in between each
one is going to be 500 meters so there our next X point will be at 500 and 4 5 6
will have the same Y so if we copy this
we can make this 4 5 6 our X is at 500 meters all right let's finish up the
remainder of our nodes so here's the remainder of our notes written out we
have 7 8 9 at 1000 same for our wise and we're going all the way down so this
defines our notes now we need to define the edges so we need to create an edge
file an edge file describes our roads and it has the extension edge edg.xml so
we'll make a new file we'll call the sumotest.edg.xml and
let's open up this edge file now we need to define our
Edge's so we will have a collection of edges so this will be edges and within
our edges collection we define our edges so our edges are going to be what
connects from one node to another node so our edges have an ID and they also
refer to the nodes as before so if we said that this edge right here that
connects one to two is e1 we would create an edge let's call the ID b1 and
it will say it connects from node 1 so our node ID from earlier we named it 1
so from 1 to 2 then you can set the priorities for 2 edges this works
because our junctions are paying attention to what edges are ending up at
the location you can also set up the number of lanes for that street so in
this case we are going to make our priority 2 and we can declare the number
of links so we can say the num lanes is 2 so there's two lanes on this edge you
can also set the speed so we can say here our speed is 14.0 this speed is in
meters per second so this is 14 meters per second which is about 31 miles per
hour we can then close our edge so this has declared edge 1 so what we would
want to do is declare every edge that is connecting from a node from one node to
another so edge 2 would be connecting from 2 to 3 and let's keep the priority
and the number of lanes and speed the same so we can update this to be edge 2
and this goes from 2 to 3 so you can finish up the remainder of the file what
I like to do personally is start with the edges going vertically
and then going horizontally now granted this is a Manhattan grid so it's a
little bit simpler this would be the completed edge file after you make all
edges first vertically which will go all the way up to 12 and then the horizontal
edges that are connecting as well there's several other optional
attributes that are available for an edge as well you can denote the shape
the length the what type of vehicles are allowed and what type of vehicles are
not allowed so those would be access permissions and you can also set the
width and then you can even go more detailed into the edge for the lanes and
set which lanes allow specific ones so if you had a lane that was bus only you
could set that lane to be allowing only buses so now that we have created our
node and edge file we can now run the sumo command net convert which will turn
the sumo test node XML file and the edge file into a network file so gonna open a
command line here and we can write net convert - - let's let it know our node
files so this would be node files equals sumo test dot node XML and then
you let it know our edge by edge - files equals sumo
Edge XML and then we let it know what the resulting output file is so you
could do -o or -- output files and declare it as sumotest.net.xml
so now we've successfully created our SUMO network if we open up our
sumotest.net.xml you can see that this is generate it it lets us know what its
inputs were and then what the output value file was and this is the resulting
SUMO network now we can also create the SUMO network
using net generate so if we go back to our command line we can use the command
netgenerate and we can specify different types of maps so net
generate works for different types of abstract networks you can create a grid
network, which is what we're gonna be doing, a spider network and random
networks. So we're creating a grid network so we would say net generate
then we give the type that we're generating this will be - - grid and
then we let it know the number of junction junctions in the x-direction
and then the number of junctions in the y-direction so if we look at our image
here we have six junctions in the X direction and three junctions in the Y
direction so we would say - - grid.x-number equals six and - - grid.y-number
equals three then we set up what our lengths would be in the X and y
direction so in our X direction our length was 500 and in our Y direction
our length is thousand so we can do -- grid.x-length equals 500 and --
grid.y-length equals 1,000 and then we would specify our output file in
this case - o and it will be sumotest we'll say 2 .net.xml so this has now
generated sumotest2.net.XML this is the result of using net generate
now you can add a bunch of different options when you're doing net generate
for instance you can set up turn lengths you can also change the default speed
the default speed is thirteen point eight nine meters per second so
you can update the default speed you can update the default priority the default
priority four is negative one which means that there really isn't a priority
and you can also update default types and you can also add a default disallows
so you can play with a lot of options within that generate we're just doing a
simple example to make that Manhattan grid
so both sumotest.net.XML and sumotest2.net.XML are roughly equivalent so now
we have made a network if we open our sumo GUI and we open our sumo test
Network we can see our network so that is our network that's our Manhattan grid
that is what we just generated and it is equivalent to the image that I showed
earlier so now we've made the network but we need to set up the simulation so
in order to create a sumo simulation we need to create at a minimum a routes
file sumo offers a Python tool called random
trips dot Python and this generates random trips for a given network and
that's why we set up this network first it will make the results out put it in a
specific trips dot XML file so let's use our random trips so we're gonna call
randomtrips.py and then we're gonna specify our network so - and to specify
the network in this case it's gonna be sumotest.net.XML then we can
specify the end time for our simulation so in this case we're gonna say there
are n time ends in 600 seconds the default is 3600. So n is 600 and
then we specify our out file so - o and we'll say this is gonna be sumotest dot
trips dot XML now this creates a random set of trips so we open up our trips
file you can see we have a trip and it tells which edge it's
going to the other edge and so on and so forth all the way up to the D part of
599 because it starts at zero so now we need to convert these trips into routes
so we can use duarouter we specify our network still so -n and this will be
sumotest.net.XML then we specify our routes file so you can you
say - - route files to specify our trips so this will be sumotest.trips.XML
and then we specify the output file so -o and it'll be sumotest.rou.XML now
not every single randomly generated trip is going to be valid and if you choose
not to ignore errors you will see every single trip that is failing so we can
add a ignore-errors and we are going to now generate our route file only
difference is I messed up the extension here that's ok can just generate our
root file now without the extension being messed up so now you will have
your sumotest rou file created it also creates an alternative route file as
well so if you open up and you look at this code you can see here is our sumo
test . rou the input was our sumo test net and also our trips our output was
our route XML and we also have an alternative output here and here are our
that our vehicles and the point that they're departing from and the edges
that they are traveling on so we can use now the route file and our network file
to set up a configuration for our sumo simulation so we have one last file to
create so we make a new call this sumotest.sumo.cfg because
this is going to be our configuration file so if we open up this we will add
our valid XML for a configuration file we actually kind of have a template
given to us in all of our generated files so we denote that this is an XML
file we specify our configuration and then we specify our inputs in this case
our input for our sumo config file is the net file and that value is gonna be
sumo test net XML and then our roots file which will be sumo test group XML
and then we also have our time which will denote the beginning and the ending
value so if we say this an open our sumo simulation in the sumo GUI it will load
up our network as before and this will be very quick so let me zoom in a little
but you can also run your simulation so you see quickly there are vehicles going
through and the simulation time stop so congratulations you've just learned how
to create a network and a simulation in sumo you can now use these sumo
configurations if your network and your root file and add them to to your veins
simulation and test other maps that you have generated on veins if you liked
what you saw please subscribe to my channel so you can get other tutorials
on OMNET++ and sumo and any other tutorials that I make as well