[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[sumo-user] Issue with Taxi Disappearing After Custom Route Completion in SUMO
|
We are currently working on a simulation involving taxis following custom routes in SUMO. However, we've encountered an issue: once the custom route is completed, the taxi disappears from the simulation—even if the passenger has not yet been picked up or dropped off. I have attached the function code for your reference, get_all_shortest_routes() will return list of list of all the possible shortest path from one edge to another.
Could you please advise on how this issue can be resolved? We would like the taxi to remain active in the simulation until the passenger is successfully dropped off, regardless of whether the custom route has ended.
Any guidance or recommendations would be greatly appreciated.
Thanks,
Jay
def controlled_routing_after_onboarding(taxi_id):
"""
Update route of taxi based on attractiveness-controlled routing
allowing max 2 diversions from shortest paths.
"""
global taxi_destinations, taxi_diversions, taxi_paths, taxi_actual_route
if taxi_id not in taxi_destinations or taxi_id not in taxi_paths:
return
current_edge = traci.vehicle.getRoadID(taxi_id)
dest_edge = taxi_destinations[taxi_id]
if current_edge == dest_edge:
return
if taxi_id not in taxi_actual_route:
taxi_actual_route[taxi_id] = [current_edge]
else:
if taxi_actual_route[taxi_id][-1] != current_edge:
taxi_actual_route[taxi_id].append(current_edge)
# Avoid modifying route if max diversions reached
if taxi_diversions.get(taxi_id, 0) >= 2:
return
# Next edge from attractiveness logic
next_edge = decide_next_edge(taxi_id, net, attractiveness_map)
if not next_edge:
return
# Check if next_edge is valid continuation
try:
# Confirm connection
path = net.getShortestPath(net.getEdge(current_edge), net.getEdge(next_edge))[0]
except Exception:
print(f"[Skip] {current_edge} to {next_edge} is not connected. Skipping reroute.")
return
# Validate against shortest paths
shortest_routes = taxi_paths[taxi_id]
valid = False
for r in shortest_routes:
if current_edge in r:
idx = r.index(current_edge)
if idx + 1 < len(r) and r[idx + 1] == next_edge:
valid = True
break
if not valid:
taxi_diversions[taxi_id] = taxi_diversions.get(taxi_id, 0) + 1
print(f"[Diversion] Taxi {taxi_id} diverted to {next_edge}. Diversions: {taxi_diversions[taxi_id]}")
# Recalculate shortest paths from new position
new_paths = get_all_shortest_routes("grid.net.xml", next_edge, dest_edge)
if new_paths:
taxi_paths[taxi_id] = new_paths
# Update route (prepend current route with new edge)
new_route = [current_edge, next_edge]
print(new_route)
traci.vehicle.setRoute(taxi_id, new_route)