When running a simulation in SUMO
with routes generated by duarouter
on a grid-like network, after a certain amount of time, the vehicles start to concentrate on the middle of the grid and in junctions due to the fact that the routes are generated using a shortest path algorithm (dijkstra
, astar
, CH
or CHWrapper
). How to generate random routes that are not created with a shortest path algorithm and do not make vehicles behave in that manner?

- 3,510
- 1
- 11
- 23

- 363
- 3
- 16
1 Answers
The usual way of preventing this is to use dynamic assignment, that is using SUMO's duaIterate.py script to calculate route distributions based on the travel time in a previous iteration of the simulation. So if you have a trip file (maybe from randomTrips.py) just call
duaIterate.py -n net.xml -t trips.xml
If you really want random routes you can try to give intermediate points (option -i
) to randomTrips.py but it will still give shortest paths between those. Alternatively you could write a simple script yourself which parses the network and the connections and tosses a coin at each junction where to drive next. In Python something like the following would do:
import random, sumolib
net = sumolib.net.readNet('myNet.net.xml')
route = [net.getEdge('startEdge')]
while len(route) < finalLength:
route.append(random.choice(route[-1].getToNode().getOutgoing()))
This code ignores that the connections or edges are maybe not usable by the vehicle type you use but I hope you get the idea. For details on using sumolib, see http://sumo.dlr.de/wiki/Tools/Sumolib

- 3,510
- 1
- 11
- 23
-
Before reading your answer I ended up creating random routes myself with the coin approach but without sumolib. Now I did the same with sumolib, thank you for your answer. – joaopaulopaiva Jun 24 '16 at 03:28