0

I am working on Veins framework, inside OMNET++ using SUMO to simulate my traffic based on the Bologna joined dataset (available at http://sumo.dlr.de/wiki/Data/Scenarios). The idea at first is to forward messages towards its destinations (a stationary point in the scenario, a RSU) using the shortest path. After that I am gonna do some improvements, but at first I need to know how to create the shortest route from a vehicle to the RSU. I've seen some people mentioning Dijkstra to do it, but probably to use Dijsktra I am gonna need a graph of the scenario and it doesn't provides the graph (probably it will be a unweighted graph). What do you recommend me to use to create the shortest routes?

So basically what i need is to implement a GPS system in my scenario to provide me the shortest path to the RSU.

Thanks!

W.Junior
  • 13
  • 5

2 Answers2

1

If your graph is unweighted you can do a simple breadth first search. The graph does not need to be provided explicitly, it suffices if you can retrieve the neighbors of each node. In Python it would look similar to the following starting from node v, looking for node rsu and having a function getNeighbors(n) providing the neighbors of n:

queue = [v]
bfsTree = {}
bfsTree[v] = None
while len(queue) > 0:
    currentNode = queue.pop(0)
    for n in getNeighbors(currentNode):
        if n not in bfsTree:
            bfsTree[n] = currentNode
            if n == rsu:
                del queue[:]
                break
            queue.append(n)
if rsu not in bfsTree:
    print("no path from v to rsu")
else:
    path = [rsu]
    while path[0] != v:
        path.insert(0, bfsTree[path[0]])
    print("shortest path from v to rsu:", path)
Michael
  • 3,510
  • 1
  • 11
  • 23
  • Thanks for the answer, but that solution seems to give the path of nodes to reach the RSU, and i need the route (name of the streets or intersections) to arrive the destination, something like what a GPS system would do. – W.Junior Nov 16 '16 at 14:37
0

If you are just looking for a shortest path in the street graph you can easily use the existing TraCI functions for that. You can change the target of the vehicle using this command http://sumo.dlr.de/wiki/TraCI/Change_Vehicle_State#change_target_.280x31.29 and then retrieve the route edges using this one http://sumo.dlr.de/wiki/TraCI/Vehicle_Value_Retrieval#Command_0xa4:_Get_Vehicle_Variable with the edges.

The corresponding functions in Veins are TraCICommandInterface::Vehicle::newRoute(std::string roadId) and TraCICommandInterface::Vehicle::getPlannedRoadIds().

Michael
  • 3,510
  • 1
  • 11
  • 23
  • Sorry for taking so long to answer, I was making some adjustments in the code and in the scenario before I could test it. It seems to be what I need, but using these functions the vehicle route will be changed, how do I prevent that to happen?. – W.Junior Nov 29 '16 at 12:40
  • You could save the old route and reset it afterwards or you add a dummy vehicle just for route calculation. – Michael Nov 29 '16 at 19:03