First of all .. Thank you very much for the help!
I tried to apply the penalties with a basic code consisting out of .setAdaptedTraveltime and search for new routes with .findRoute . But unfortunately when I want to .setRoute the new route of .findRoute, I get an error. Furthermore the actually supposed
to be different routes (route_1,route_2 and route_3) are all the same. So my questions for the code below:
Q1: Why is the setRoute function not working for the .findRoute --> new_route ?
Q2: Why is findRoute not finding different routes due to the penalyzed weights of the edges with setAdaptedTraveltime?
Q3: Is the findRoute using the currentTravelTimes like reroute and if not, how is it possible?
Q4: How can I set the adapedTraveltime back to the current after finding a new route?
def run():
step = 0
while traci.simulation.getMinExpectedNumber() >0:
traci.simulationStep()
print(step)
step+=1
det_vehs = traci.inductionloop.getLastStepVehicleIDs("det_0") #creates an induction loop
IDlist = traci.vehicle.getIDList() #creates a list of all current vehicle in the simulation
assign = 1
if step > 40:
for veh in det_vehs:
traci.vehicle.setSpeed(veh, 0.0) #sets the speed of the vehicle,
# which drives on the induction loop, to zero
for veh_1 in IDlist:
traci.vehicle.setRoutingMode(veh_1, 1) #sets the RoutingMode to aggregated
#traci.vehicle.rerouteTraveltime(veh_1) #reroutes the vehicles
current_start = traci.vehicle.getRoadID(veh_1)
trip = traci.vehicle.getRoute(veh_1)
end = trip[-1]
if assign == 1: #assignment on/off
route_inf_1 = traci.simulation.findRoute(current_start, end) #findRoute with all information
route_1 = route_inf_1[4] #just list of edges of findRoute
for edges1 in route_1: #penalyzing
traci.vehicle.setAdaptedTraveltime(veh_1, edges1, 90.0)
route__inf_2 = traci.simulation.findRoute(current_start, end) #new route find with penalyzed
route_2 = route__inf_2[4] #just list of edges of findRoute
for edges2 in route_2:
traci.vehicle.setAdaptedTraveltime(veh_1, edges2, 90.0 ) #penalyzing
route_inf_3 = traci.simulation.findRoute(current_start, end) #new route find with penalyzed
route_3 = route_inf_3[4] #just list of edges of findRoute
new_route = random.choice([route_1, route_2, route_3])
if len(new_route) > 1: #check vehicle is at final
traci.vehicle.setRoute(veh_1, new_route)
traci.close()
sys.stdout.flush()
--> Error:
Traceback (most recent call last):
File "G:/TE-F1/Studenten/Hoffmann_Pascal/04_Simulation/ma_routing_via_traci/input.py", line 78, in <module>
run()
File "G:/TE-F1/Studenten/Hoffmann_Pascal/04_Simulation/ma_routing_via_traci/input.py", line 61, in run
traci.vehicle.setRoute(veh_1, new_route)
File "C:\Program Files (x86)\Eclipse\Sumo\tools\traci\_vehicle.py", line 1124, in setRoute
self._connection._sendExact()
File "C:\Program Files (x86)\Eclipse\Sumo\tools\traci\connection.py", line 112, in _sendExact
raise TraCIException(err, prefix[1], _RESULTS[prefix[2]])
traci.exceptions.TraCIException: Route replacement failed for carflow_1.1