Skip to content

Commit

Permalink
Consider distance from distance dimension rather than entire cost in …
Browse files Browse the repository at this point in the history
…cvrp_reload (#4522)
  • Loading branch information
arnabanimesh authored Jan 27, 2025
1 parent 5e68e51 commit 95c13bf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion examples/notebook/routing/cvrp_reload.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@
" total_time = 0\n",
" capacity_dimension = routing.GetDimensionOrDie(\"Capacity\")\n",
" time_dimension = routing.GetDimensionOrDie(\"Time\")\n",
" distance_dimension = routing.GetDimensionOrDie(\"Distance\")\n",
" dropped = []\n",
" for order in range(6, routing.nodes()):\n",
" index = manager.NodeToIndex(order)\n",
Expand Down Expand Up @@ -411,7 +412,7 @@
" )\n",
" previous_index = index\n",
" index = assignment.Value(routing.NextVar(index))\n",
" distance += routing.GetArcCostForVehicle(previous_index, index, vehicle_id)\n",
" distance += distance_dimension.GetTransitValue(previous_index, index, vehicle_id)\n",
" load_var = capacity_dimension.CumulVar(index)\n",
" time_var = time_dimension.CumulVar(index)\n",
" plan_output += (\n",
Expand Down
3 changes: 2 additions & 1 deletion ortools/routing/samples/cvrp_reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ def print_solution(
total_time = 0
capacity_dimension = routing.GetDimensionOrDie("Capacity")
time_dimension = routing.GetDimensionOrDie("Time")
distance_dimension = routing.GetDimensionOrDie("Distance")
dropped = []
for order in range(6, routing.nodes()):
index = manager.NodeToIndex(order)
Expand Down Expand Up @@ -344,7 +345,7 @@ def print_solution(
)
previous_index = index
index = assignment.Value(routing.NextVar(index))
distance += routing.GetArcCostForVehicle(previous_index, index, vehicle_id)
distance += distance_dimension.GetTransitValue(previous_index, index, vehicle_id)
load_var = capacity_dimension.CumulVar(index)
time_var = time_dimension.CumulVar(index)
plan_output += (
Expand Down

0 comments on commit 95c13bf

Please sign in to comment.