Skip to content

Commit 8857a64

Browse files
authored
Consider distance from distance dimension rather than entire cost in cvrp_reload
1 parent 56817ee commit 8857a64

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

examples/notebook/routing/cvrp_reload.ipynb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@
384384
" total_time = 0\n",
385385
" capacity_dimension = routing.GetDimensionOrDie(\"Capacity\")\n",
386386
" time_dimension = routing.GetDimensionOrDie(\"Time\")\n",
387+
" distance_dimension = routing.GetDimensionOrDie(\"Distance\")\n",
387388
" dropped = []\n",
388389
" for order in range(6, routing.nodes()):\n",
389390
" index = manager.NodeToIndex(order)\n",
@@ -410,7 +411,7 @@
410411
" )\n",
411412
" previous_index = index\n",
412413
" index = assignment.Value(routing.NextVar(index))\n",
413-
" distance += routing.GetArcCostForVehicle(previous_index, index, vehicle_id)\n",
414+
" distance += distance_dimension.GetTransitValue(previous_index, index, vehicle_id)\n",
414415
" load_var = capacity_dimension.CumulVar(index)\n",
415416
" time_var = time_dimension.CumulVar(index)\n",
416417
" plan_output += (\n",
@@ -490,7 +491,11 @@
490491
]
491492
}
492493
],
493-
"metadata": {},
494+
"metadata": {
495+
"language_info": {
496+
"name": "python"
497+
}
498+
},
494499
"nbformat": 4,
495500
"nbformat_minor": 5
496501
}

ortools/routing/samples/cvrp_reload.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ def print_solution(
317317
total_time = 0
318318
capacity_dimension = routing.GetDimensionOrDie("Capacity")
319319
time_dimension = routing.GetDimensionOrDie("Time")
320+
distance_dimension = routing.GetDimensionOrDie("Distance")
320321
dropped = []
321322
for order in range(6, routing.nodes()):
322323
index = manager.NodeToIndex(order)
@@ -343,7 +344,7 @@ def print_solution(
343344
)
344345
previous_index = index
345346
index = assignment.Value(routing.NextVar(index))
346-
distance += routing.GetArcCostForVehicle(previous_index, index, vehicle_id)
347+
distance += distance_dimension.GetTransitValue(previous_index, index, vehicle_id)
347348
load_var = capacity_dimension.CumulVar(index)
348349
time_var = time_dimension.CumulVar(index)
349350
plan_output += (

0 commit comments

Comments
 (0)