Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SumoTrafficSimulation route transfer. #2014

Merged

Conversation

Gamenot
Copy link
Collaborator

@Gamenot Gamenot commented May 4, 2023

Closes #2011

@Gamenot Gamenot changed the title Fix routing issues. Fix SumoTrafficSimulation routing issues. May 4, 2023
@Gamenot Gamenot changed the title Fix SumoTrafficSimulation routing issues. Fix SumoTrafficSimulation route transfer. May 4, 2023
if not self.connected:
return None
try:
route = self._traci_conn.vehicle.getRoute(vehicle_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note on self._traci_conn.vehicle.getRoute(vehicle_id)

The TraCI getRoute method returns edge ids which form the vehicle's route, but any junctions in the route are not included. Hence, total route distance calculation using getRoute method results in a shorter distance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the public facing method we should be resolving it to a full route using the road map.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following original issues appears to be resolved by this PR.

  • Issue-1: In all remaining steps within that episode, both SumoTrafficSimulation and LocalTrafficProvider appear to be managing "Leader-007".
  • Issue-2: The destination road of "Leader-007" appears to have changed from E4 under SumoTrafficSimulation control to E2.224.85 when controlled by LocalTrafficProvider.

Below we use the public methods of SumoTrafficSimulation to compute the route distance.

route = traffic_sim.route_for_vehicle(vehicle_name)
for r in route.road_ids:
    print(r)
dist_tot = route.road_length
  • Prior to this PR, the public method route_for_vehicle had internally called self._traci_conn.vehicle.getRoute(vehicle_id) which resulted in it returning a shorter route distance.
  • Now, including code changes in this PR, the public methods above still appear to return shorter route distance and does not include junctions in the route.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I was under the assumption that RoadMap.route_from_road_ids(road_ids) would resolve the full route.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracing the call chain, we see roads added without resolving junctions.
SumoTrafficSimulation.route_for_vehicle() -> SumoRoadNetwork.route_from_road_ids() -> SumoRoadNetwork.Route.from_road_ids()

@classmethod
def from_road_ids(
cls, road_map: RoadMap, road_ids: Sequence[str]
) -> "RouteWithCache":
"""Factory to generate a new RouteWithCache from a sequence of road ids."""
route = cls(road_map)
for road_id in road_ids:
road = road_map.road_by_id(road_id)
assert road, f"cannot add unknown road {road_id} to route"
route._add_road(road)
return route

Similarly, junctions appear to be excluded resulting in a shorter distance in the public method of Smarts traffic provider LocalTrafficProvider.route_for_vehicle(vehicle_name).

We may merge this PR, and track this issue in a separate thread.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a fix for getting the full route.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may still result in a shorter length perhaps but the junctions will be included.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fixed SumoTrafficSimulation.route_for_vehicle().road_length now returns the full length of all the roads (including junctions) in the route, ignoring the starting offset.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be some consideration in the future if to add the initial and end offsets as necessary attributes of a route.

@Gamenot Gamenot merged commit e7409c9 into master May 4, 2023
@Gamenot Gamenot deleted the tucker/bugfix-sumo-traffic-simulation-route-transfer branch May 4, 2023 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Traffic handover: Vehicle destination changed and is managed by multiple traffic providers
3 participants