Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't add negative load during reloading at depots when calculat… #4521

Merged
merged 5 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions examples/notebook/routing/cvrp_reload.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -401,31 +401,34 @@
" for vehicle_id in range(data[\"num_vehicles\"]):\n",
" index = routing.Start(vehicle_id)\n",
" plan_output = f\"Route for vehicle {vehicle_id}:\\n\"\n",
" load_value = 0\n",
" distance = 0\n",
" while not routing.IsEnd(index):\n",
" load_var = capacity_dimension.CumulVar(index)\n",
" time_var = time_dimension.CumulVar(index)\n",
" plan_output += (\n",
" f\" {manager.IndexToNode(index)} \"\n",
" f\"Load({assignment.Min(load_var)}) \"\n",
" f\"Load({assignment.Min(capacity_dimension.CumulVar(index))}) \"\n",
" f\"Time({assignment.Min(time_var)},{assignment.Max(time_var)}) ->\"\n",
" )\n",
" previous_index = index\n",
" index = assignment.Value(routing.NextVar(index))\n",
" distance += distance_dimension.GetTransitValue(previous_index, index, vehicle_id)\n",
" load_var = capacity_dimension.CumulVar(index)\n",
" # capacity dimension TransitVar is negative at reload stations during replenishment\n",
" # don't want to consider those values when calculating the total load of the route\n",
" # hence only considering the positive values\n",
" load_value += max(0, capacity_dimension.GetTransitValue(previous_index, index, vehicle_id))\n",
" time_var = time_dimension.CumulVar(index)\n",
" plan_output += (\n",
" f\" {manager.IndexToNode(index)} \"\n",
" f\"Load({assignment.Min(load_var)}) \"\n",
" f\"Load({assignment.Min(capacity_dimension.CumulVar(index))}) \"\n",
" f\"Time({assignment.Min(time_var)},{assignment.Max(time_var)})\\n\"\n",
" )\n",
" plan_output += f\"Distance of the route: {distance}m\\n\"\n",
" plan_output += f\"Load of the route: {assignment.Min(load_var)}\\n\"\n",
" plan_output += f\"Load of the route: {load_value}\\n\"\n",
" plan_output += f\"Time of the route: {assignment.Min(time_var)}min\\n\"\n",
" print(plan_output)\n",
" total_distance += distance\n",
" total_load += assignment.Min(load_var)\n",
" total_load += load_value\n",
" total_time += assignment.Min(time_var)\n",
" print(f\"Total Distance of all routes: {total_distance}m\")\n",
" print(f\"Total Load of all routes: {total_load}\")\n",
Expand Down
15 changes: 9 additions & 6 deletions ortools/routing/samples/cvrp_reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,31 +334,34 @@ def print_solution(
for vehicle_id in range(data["num_vehicles"]):
index = routing.Start(vehicle_id)
plan_output = f"Route for vehicle {vehicle_id}:\n"
load_value = 0
distance = 0
while not routing.IsEnd(index):
load_var = capacity_dimension.CumulVar(index)
time_var = time_dimension.CumulVar(index)
plan_output += (
f" {manager.IndexToNode(index)} "
f"Load({assignment.Min(load_var)}) "
f"Load({assignment.Min(capacity_dimension.CumulVar(index))}) "
f"Time({assignment.Min(time_var)},{assignment.Max(time_var)}) ->"
)
previous_index = index
index = assignment.Value(routing.NextVar(index))
distance += distance_dimension.GetTransitValue(previous_index, index, vehicle_id)
load_var = capacity_dimension.CumulVar(index)
# capacity dimension TransitVar is negative at reload stations during replenishment
# don't want to consider those values when calculating the total load of the route
# hence only considering the positive values
load_value += max(0, capacity_dimension.GetTransitValue(previous_index, index, vehicle_id))
time_var = time_dimension.CumulVar(index)
plan_output += (
f" {manager.IndexToNode(index)} "
f"Load({assignment.Min(load_var)}) "
f"Load({assignment.Min(capacity_dimension.CumulVar(index))}) "
f"Time({assignment.Min(time_var)},{assignment.Max(time_var)})\n"
)
plan_output += f"Distance of the route: {distance}m\n"
plan_output += f"Load of the route: {assignment.Min(load_var)}\n"
plan_output += f"Load of the route: {load_value}\n"
plan_output += f"Time of the route: {assignment.Min(time_var)}min\n"
print(plan_output)
total_distance += distance
total_load += assignment.Min(load_var)
total_load += load_value
total_time += assignment.Min(time_var)
print(f"Total Distance of all routes: {total_distance}m")
print(f"Total Load of all routes: {total_load}")
Expand Down