From 95c13bf27ebb16bdd27d88faf1a4d52481a5d0d3 Mon Sep 17 00:00:00 2001 From: Arnab Animesh Das Date: Mon, 27 Jan 2025 19:49:36 +0530 Subject: [PATCH] Consider distance from distance dimension rather than entire cost in cvrp_reload (#4522) --- examples/notebook/routing/cvrp_reload.ipynb | 3 ++- ortools/routing/samples/cvrp_reload.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/notebook/routing/cvrp_reload.ipynb b/examples/notebook/routing/cvrp_reload.ipynb index 47ab0bb7a9..54130a281e 100644 --- a/examples/notebook/routing/cvrp_reload.ipynb +++ b/examples/notebook/routing/cvrp_reload.ipynb @@ -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", @@ -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", diff --git a/ortools/routing/samples/cvrp_reload.py b/ortools/routing/samples/cvrp_reload.py index 1f392315d3..d73568df7e 100755 --- a/ortools/routing/samples/cvrp_reload.py +++ b/ortools/routing/samples/cvrp_reload.py @@ -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) @@ -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 += (