Skip to content

Commit

Permalink
Allow overriding the vehicle fixed cost in the initial local model fr…
Browse files Browse the repository at this point in the history
…om command-line flags.

To make multiple time windows per shipment work well in the two-step routing
library, the vehicle fixed cost in the initial local model must be low, so that
the solver doesn't have a tendency to create very long routes that span across
all the time windows. Such routes do not cause any errors, but they can block
the concerned vehicle for the whole time between the two time windows.
  • Loading branch information
ondrasej committed Feb 6, 2024
1 parent e6e4a27 commit 61a3088
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions python/cfr/two_step_routing/two_step_routing_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class Flags:
end_with_local_refinement: The value of the --end_with_local_refinement
flag.
local_grouping: The value of the --local_grouping flag or the default value.
local_model_vehicle_fixed_cost: The value of the
--local_model_vehicle_fixed_cost flag.
travel_mode_in_merged_transitions: The value of the
--travel_mode_in_merged_transitions flag.
inject_start_times_to_refinement_first_solution: The value of the
Expand All @@ -78,6 +80,7 @@ class Flags:
num_refinements: int
end_with_local_refinement: bool
local_grouping: two_step_routing.LocalModelGrouping
local_model_vehicle_fixed_cost: float | None
travel_mode_in_merged_transitions: bool
inject_start_times_to_refinement_first_solution: bool
local_timeout: cfr_json.DurationString
Expand Down Expand Up @@ -119,6 +122,15 @@ def _parse_flags() -> Flags:
help="Controls the grouping mode in the local model.",
default=two_step_routing.LocalModelGrouping.PARKING_AND_TIME,
)
parser.add_argument(
"--local_model_vehicle_fixed_cost",
default=None,
type=float,
help=(
"The cost of a vehicle in the initial local model. When None, the"
" default cost determined by the solver is used."
),
)
parser.add_argument(
"--travel_mode_in_merged_transitions",
help="Add travel mode information to transitions in the merged solution.",
Expand Down Expand Up @@ -206,6 +218,7 @@ def _parse_flags() -> Flags:
google_cloud_token=flags.token,
local_timeout=flags.local_timeout,
local_grouping=flags.local_grouping,
local_model_vehicle_fixed_cost=flags.local_model_vehicle_fixed_cost,
travel_mode_in_merged_transitions=flags.travel_mode_in_merged_transitions,
inject_start_times_to_refinement_first_solution=flags.inject_start_times_to_refinement_first_solution,
global_timeout=flags.global_timeout,
Expand Down Expand Up @@ -342,6 +355,10 @@ def _run_two_step_planner() -> None:
raise ValueError(
"Unexpected value of --local_grouping: {flags.local_grouping!r}"
)
if flags.local_model_vehicle_fixed_cost is not None:
options.local_model_vehicle_fixed_cost = (
flags.local_model_vehicle_fixed_cost
)

planner = two_step_routing.Planner(
request_json, parking_locations, parking_for_shipment, options
Expand Down

0 comments on commit 61a3088

Please sign in to comment.