def getTrips(edgeSrc, edgeDest, junctionsDict): """ Returns a list of edges ID containing edges pairs. Each pair represent routing demand by a source and destination edge ID. This list is built from a source edge ID, a destination edge ID and a junction dictionary(*) """ if isJunction(edgeSrc): src = list(junctionsDict[getJunctionId(edgeSrc)][0])[0] else: src = edgeSrc if isJunction(edgeDest): dest = list(junctionsDict[getJunctionId(edgeDest)][1])[0] else: dest = edgeDest return [src, dest]
def processRouteRequest(src, destinations, junctionsDict, graphDict): """ - Transforms the source and destination coordinates to SUMO junctions ID - Resolves the routing demand by using a dijkstra algorithm - Sends the route (list of geographic coordinates) back to the client """ route = [] first = True if isJunction(src): #src become an edge predecessor of the src junction src = iter(junctionsDict[getJunctionId(src)][0]).next() srcJunction = True else: srcJunction = False for dest in destinations: if isJunction(dest): #dest become an edge successor of the dest junction dest = iter(junctionsDict[getJunctionId(dest)][1]).next() destJunction = True else: destJunction = False try: #Getting shortest path tmpRoute = dijkstra.shortestPath(graphDict, src, dest) except Exception as e: Logger.exception(e) return constants.ROUTE_ERROR_CONNECTION, None #Removing the first edge if it's the first routing and we find recurrence if first and srcJunction and tmpRoute: tmpRoute.pop(0) elif first and len(tmpRoute) > 1 and tmpRoute[1] == getOppositeEdge( tmpRoute[0]): tmpRoute.pop(0) #Removing the last edge if it was a junctions from start if destJunction and tmpRoute: tmpRoute.pop() #Removing the first edge of routings with via points in order to avoid two identical edges when extending road if not first: tmpRoute.pop(0) #Adding the calculated routing to the main routing route.extend(tmpRoute) first = False #Updating source edge for the next routing if tmpRoute: src = tmpRoute[-1] else: src = dest if len(route) > 1 and route[-2] == getOppositeEdge(route[-1]): route.pop() return 0, route
def updateTllForPriorityVehicles(mtraci, priorityVehicles, mPriorityVehicles, tllDict, yellowTllDict, managedTllDict): """ Determines for each priority vehicle which are the next traffic lights and the distance to these ones. Regarding to the vehicle current speed and the time elapsed during a SUMO simulation step, the traffic light hidden lane the vehicle will cross is set to green or the junction to a temporary orange state if the vehicle is close enough and if the concurrent access between priority vehicles allows it. Note: the following algorithm could be highly improved by exploring every edges the vehicle will use at the beginning, but then only explore the edges which are now in the vehicle scope because of the last step progression. Two list, one for the orange look up and one for the green, would be used for this purpose. Note 2: The main complexity of this algorithm resides in the lack of TraCI functionalities in order to get retrieve the state of a hidden lane linking two lanes. This could also be highly improved by using a dictionary built when starting the software. """ mPriorityVehicles.acquire() managedTlls = [] length = len(priorityVehicles) # Checking if the next traffic light has to be changed for each priority vehicleId in the simulation for prioVehIndex in range(0, length): vehicleId = priorityVehicles[prioVehIndex] # Getting route and position information for the current priority vehicleId mtraci.acquire() route = traci.vehicle.getRoute(vehicleId) currentLane = traci.vehicle.getLaneID(vehicleId) mtraci.release() if currentLane != '' and not isJunction(currentLane): # Getting speed information for space and time predictions mtraci.acquire() lanePosition = traci.vehicle.getLanePosition(vehicleId) laneLength = traci.lane.getLength(currentLane) mtraci.release() currentEdge = getEdgeFromLane(currentLane) currentEdgeIndex = route.index(currentEdge) remainingLength = laneLength - lanePosition edge = currentEdge lane = currentLane edgeIndex = currentEdgeIndex # Browsing the next edges the vehicleId will go to while remainingLength <= constants.YELLOW_LENGTH_ANTICIPATION and edgeIndex < len( route) - 1: # If the current edge (the vehicleId is not) ends with a traffic light if edge in tllDict: # If the car is close enough for the traffic light to become green if remainingLength <= constants.GREEN_LENGTH_ANTICIPATION: setState = constants.SET_GREEN # If the car is close enough for the traffic light to prepare (temporary state) becoming green elif not tllDict[edge] in yellowTllDict: setState = constants.SET_YELLOW else: managedTlls.append(tllDict[edge]) setState = constants.IGNORE # Calculating the next lane the vehicleId will go to outEdge = route[edgeIndex + 1] outLane = getOutLane(mtraci, lane, outEdge) # Calling for a traffic light change if outLane != -1 and setState != constants.IGNORE: tllId = tllDict[edge] managedTlls.append(tllId) if (tllId in managedTllDict and managedTllDict[tllId][1] > remainingLength ) or not tllId in managedTllDict: managedTllDict[tllId] = (vehicleId, remainingLength) changeState(mtraci, tllId, lane, outLane, setState, yellowTllDict) edgeIndex += 1 if edgeIndex < len(route): edge = route[edgeIndex] lane = getFirstLaneFromEdge(edge) mtraci.acquire() laneLength = traci.lane.getLength(lane) mtraci.release() remainingLength += laneLength # Removing the tlls which have been crossed from the managedTllDict for key in managedTllDict.keys(): if managedTllDict[key][ 0] == vehicleId and not key in managedTlls: del managedTllDict[key] managedTlls[:] = [] mPriorityVehicles.release()
def processRouteRequest(src, destinations, junctionsDict): """ - Transforms the source and destination coordinates to SUMO edges ID - Resolves the routing demand by using DUAROUTER - Sends the route (list of geographic coordinates) back to the client """ route = [] first = True if isJunction(src): #src become an edge predecessor of the src junction src = iter(junctionsDict[getJunctionId(src)][0]).next() srcJunction = True else: srcJunction = False for dest in destinations: if isJunction(dest): #dest become an edge successor of the dest junction dest = iter(junctionsDict[getJunctionId(dest)][1]).next() destJunction = True else: destJunction = False #Removing temporary routing files removeRoutingFiles() #Writing them in an XML file writeTrips([src, dest]) #Running Duarouter returnCode = runDuarouterRouteSolver() if returnCode != 0: return returnCode, None #Getting the best route from the XML result file returnCode, tmpRoute = getBestRouteFromXml() if returnCode !=0: return returnCode, None #Removing the first edge if it's the first routing and we find recurrence if first and srcJunction and tmpRoute: tmpRoute.pop(0) elif first and len(tmpRoute) > 1 and tmpRoute[1] == getOppositeEdge(tmpRoute[0]): tmpRoute.pop(0) #Removing the last edge if it was a junctions from start if destJunction and tmpRoute: tmpRoute.pop() #Removing the first edge of routings with via points in order to avoid two identical edges when extending road if not first: tmpRoute.pop(0) #Adding the calculated routing to the main routing route.extend(tmpRoute) first = False #Updating source edge for the next routing if tmpRoute: src = tmpRoute[-1] else: src = dest if len(route) > 1 and route[-2] == getOppositeEdge(route[-1]): route.pop() return 0, route
def processRouteRequest(src, destinations, junctionsDict): """ - Transforms the source and destination coordinates to SUMO edges ID - Resolves the routing demand by using DUAROUTER - Sends the route (list of geographic coordinates) back to the client """ route = [] first = True if isJunction(src): #src become an edge predecessor of the src junction src = iter(junctionsDict[getJunctionId(src)][0]).next() srcJunction = True else: srcJunction = False for dest in destinations: if isJunction(dest): #dest become an edge successor of the dest junction dest = iter(junctionsDict[getJunctionId(dest)][1]).next() destJunction = True else: destJunction = False #Removing temporary routing files removeRoutingFiles() #Writing them in an XML file writeTrips([src, dest]) #Running Duarouter returnCode = runDuarouterRouteSolver() if returnCode != 0: return returnCode, None #Getting the best route from the XML result file returnCode, tmpRoute = getBestRouteFromXml() if returnCode != 0: return returnCode, None #Removing the first edge if it's the first routing and we find recurrence if first and srcJunction and tmpRoute: tmpRoute.pop(0) elif first and len(tmpRoute) > 1 and tmpRoute[1] == getOppositeEdge( tmpRoute[0]): tmpRoute.pop(0) #Removing the last edge if it was a junctions from start if destJunction and tmpRoute: tmpRoute.pop() #Removing the first edge of routings with via points in order to avoid two identical edges when extending road if not first: tmpRoute.pop(0) #Adding the calculated routing to the main routing route.extend(tmpRoute) first = False #Updating source edge for the next routing if tmpRoute: src = tmpRoute[-1] else: src = dest if len(route) > 1 and route[-2] == getOppositeEdge(route[-1]): route.pop() return 0, route
def processRouteRequest(src, destinations, junctionsDict, graphDict): """ - Transforms the source and destination coordinates to SUMO junctions ID - Resolves the routing demand by using a dijkstra algorithm - Sends the route (list of geographic coordinates) back to the client """ route = [] first = True if isJunction(src): #src become an edge predecessor of the src junction src = iter(junctionsDict[getJunctionId(src)][0]).next() srcJunction = True else: srcJunction = False for dest in destinations: if isJunction(dest): #dest become an edge successor of the dest junction dest = iter(junctionsDict[getJunctionId(dest)][1]).next() destJunction = True else: destJunction = False try: #Getting shortest path tmpRoute = dijkstra.shortestPath(graphDict, src, dest) except Exception as e: Logger.exception(e) return constants.ROUTE_ERROR_CONNECTION, None #Removing the first edge if it's the first routing and we find recurrence if first and srcJunction and tmpRoute: tmpRoute.pop(0) elif first and len(tmpRoute) > 1 and tmpRoute[1] == getOppositeEdge(tmpRoute[0]): tmpRoute.pop(0) #Removing the last edge if it was a junctions from start if destJunction and tmpRoute: tmpRoute.pop() #Removing the first edge of routings with via points in order to avoid two identical edges when extending road if not first: tmpRoute.pop(0) #Adding the calculated routing to the main routing route.extend(tmpRoute) first = False #Updating source edge for the next routing if tmpRoute: src = tmpRoute[-1] else: src = dest if len(route) > 1 and route[-2] == getOppositeEdge(route[-1]): route.pop() return 0, route
def updateTllForPriorityVehicles(mtraci, priorityVehicles, mPriorityVehicles, tllDict, yellowTllDict, managedTllDict): """ Determines for each priority vehicle which are the next traffic lights and the distance to these ones. Regarding to the vehicle current speed and the time elapsed during a SUMO simulation step, the traffic light hidden lane the vehicle will cross is set to green or the junction to a temporary orange state if the vehicle is close enough and if the concurrent access between priority vehicles allows it. Note: the following algorithm could be highly improved by exploring every edges the vehicle will use at the beginning, but then only explore the edges which are now in the vehicle scope because of the last step progression. Two list, one for the orange look up and one for the green, would be used for this purpose. Note 2: The main complexity of this algorithm resides in the lack of TraCI functionalities in order to get retrieve the state of a hidden lane linking two lanes. This could also be highly improved by using a dictionary built when starting the software. """ mPriorityVehicles.acquire() managedTlls = []; length = len(priorityVehicles) # Checking if the next traffic light has to be changed for each priority vehicleId in the simulation for prioVehIndex in range(0, length): vehicleId = priorityVehicles[prioVehIndex] # Getting route and position information for the current priority vehicleId mtraci.acquire() route = traci.vehicle.getRoute(vehicleId) currentLane = traci.vehicle.getLaneID(vehicleId) mtraci.release() if currentLane != '' and not isJunction(currentLane): # Getting speed information for space and time predictions mtraci.acquire() lanePosition = traci.vehicle.getLanePosition(vehicleId) laneLength = traci.lane.getLength(currentLane) mtraci.release() currentEdge = getEdgeFromLane(currentLane) currentEdgeIndex = route.index(currentEdge) remainingLength = laneLength - lanePosition edge = currentEdge lane = currentLane edgeIndex = currentEdgeIndex # Browsing the next edges the vehicleId will go to while remainingLength <= constants.YELLOW_LENGTH_ANTICIPATION and edgeIndex < len(route) - 1: # If the current edge (the vehicleId is not) ends with a traffic light if edge in tllDict: # If the car is close enough for the traffic light to become green if remainingLength <= constants.GREEN_LENGTH_ANTICIPATION: setState = constants.SET_GREEN # If the car is close enough for the traffic light to prepare (temporary state) becoming green elif not tllDict[edge] in yellowTllDict: setState = constants.SET_YELLOW else: managedTlls.append(tllDict[edge]) setState = constants.IGNORE # Calculating the next lane the vehicleId will go to outEdge = route[edgeIndex + 1] outLane = getOutLane(mtraci, lane, outEdge) # Calling for a traffic light change if outLane != -1 and setState != constants.IGNORE: tllId = tllDict[edge] managedTlls.append(tllId) if (tllId in managedTllDict and managedTllDict[tllId][1] > remainingLength) or not tllId in managedTllDict: managedTllDict[tllId] = (vehicleId, remainingLength) changeState(mtraci, tllId, lane, outLane, setState, yellowTllDict) edgeIndex += 1 if edgeIndex < len(route): edge = route[edgeIndex] lane = getFirstLaneFromEdge(edge) mtraci.acquire() laneLength = traci.lane.getLength(lane) mtraci.release() remainingLength += laneLength # Removing the tlls which have been crossed from the managedTllDict for key in managedTllDict.keys(): if managedTllDict[key][0] == vehicleId and not key in managedTlls: del managedTllDict[key] managedTlls[:] = [] mPriorityVehicles.release()