Skip to content

Commit

Permalink
[two_step_routing] Adapted the two-step library to support u-turn avo…
Browse files Browse the repository at this point in the history
…idance.
  • Loading branch information
ondrasej committed Sep 8, 2024
1 parent b5779fd commit 1772cb6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/gmpro/json/cfr_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class VisitRequest(TypedDict, total=False):
timeWindows: list[TimeWindow]
duration: DurationString
cost: float
avoidUTurns: bool

tags: list[str]

Expand Down Expand Up @@ -235,6 +236,7 @@ class Visit(TypedDict, total=False):
detour: str
isPickup: bool
visitRequestIndex: int
injectedSolutionLocationToken: int


class EncodedPolyline(TypedDict, total=False):
Expand Down
14 changes: 14 additions & 0 deletions python/gmpro/two_step_routing/two_step_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@ def _integrate_global_skipped_shipments(self) -> None:
visit_detour=None,
is_pickup=None,
visit_request_index=None,
injected_solution_location_token=None,
)
)
case "p":
Expand Down Expand Up @@ -1185,6 +1186,9 @@ def _integrate_global_routes(self) -> None:
visit_detour = global_visit["detour"]
is_pickup = global_visit.get("isPickup", False)
visit_request_index = global_visit.get("visitRequestIndex", 0)
injected_solution_location_token = global_visit.get(
"injectedSolutionLocationToken"
)
match visit_type:
case "s":
self._add_integrated_global_shipment(
Expand All @@ -1194,6 +1198,7 @@ def _integrate_global_routes(self) -> None:
visit_detour=visit_detour,
is_pickup=is_pickup,
visit_request_index=visit_request_index,
injected_solution_location_token=injected_solution_location_token,
)
case "p":
self._integrate_unmodified_local_route(
Expand Down Expand Up @@ -1419,6 +1424,7 @@ def _integrate_refined_local_route(
# delivery visit request.
is_pickup=False,
visit_request_index=0,
injected_solution_location_token=None,
)

def _integrate_unmodified_local_route(
Expand Down Expand Up @@ -1484,6 +1490,7 @@ def _integrate_unmodified_local_route(
visit_detour=visit_detour,
is_pickup=None if add_to_visits is None else False,
visit_request_index=None if add_to_visits is None else 0,
injected_solution_location_token=None,
)

def _add_integrated_global_shipment(
Expand All @@ -1496,6 +1503,7 @@ def _add_integrated_global_shipment(
# visits are always delivery-only, and they have exactly one delivery
# visit request.
visit_request_index: int | None,
injected_solution_location_token: int | None,
is_pickup: bool | None,
) -> int:
"""Adds `shipment` to the integrated request and returns its index.
Expand All @@ -1509,6 +1517,8 @@ def _add_integrated_global_shipment(
visit_detour: The detour of the visit for the new shipment in the
integrated global model. Must be None exactly when `add_to_visits` is
None.
injected_solution_location_token: The location token associated with this
visit or None, if no token is needed.
Returns:
The index of the newly added integrated shipment.
Expand Down Expand Up @@ -1537,6 +1547,10 @@ def _add_integrated_global_shipment(
"shipmentLabel": shipment.get("label", ""),
"isPickup": is_pickup,
}
if injected_solution_location_token is not None:
visit["injectedSolutionLocationToken"] = (
injected_solution_location_token
)
if visit_request_index:
visit["visitRequestIndex"] = visit_request_index
if is_pickup:
Expand Down

0 comments on commit 1772cb6

Please sign in to comment.