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

Inactive trucks should not be shown in the output #4520

Merged
merged 6 commits into from
Jan 28, 2025

Conversation

arnabanimesh
Copy link
Contributor

@arnabanimesh arnabanimesh commented Jan 25, 2025

No description provided.

Copy link
Collaborator

@Mizux Mizux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Mizux
Copy link
Collaborator

Mizux commented Jan 26, 2025

Will merge it on Monday, want to perform the same fix on the C++, Java and .Net samples if any...

@Mizux Mizux self-assigned this Jan 26, 2025
@Mizux Mizux added this to the v9.12 milestone Jan 26, 2025
@Mizux Mizux added Bug Solver: Routing Uses the Routing library and the original CP solver labels Jan 26, 2025
@arnabanimesh
Copy link
Contributor Author

Updated the Python notebook as well

@lperron
Copy link
Collaborator

lperron commented Jan 26, 2025

@arnabanimesh
Copy link
Contributor Author

arnabanimesh commented Jan 26, 2025

Not sure, see https://developers.google.com/optimization/routing/routing_tasks#allowing_arbitrary_start_and_end_locations

It is just to have a cleaner output. If a truck is not leaving the depot (i.e. it is not visiting any customer and delivering), then there's no point showing it in the print output.

A fleet might have 100 trucks as per the input data. However, the solver might be able to visit all locations and arrive at a solution using 25 trucks. What's the point of showing the rest of the 75 trucks when they are not doing anything? They will simply clutter the output.

@arnabanimesh arnabanimesh requested a review from Mizux January 26, 2025 22:38
@Mizux Mizux added Feature Request Missing Feature/Wrapper Lang: Python Python wrapper issue and removed Bug labels Jan 27, 2025
@Mizux
Copy link
Collaborator

Mizux commented Jan 27, 2025

Actually, it should be better to use: routing.ActiveVehicleVar(vehicle_idx) to check if vehicle is used

/// Returns the active variable of the vehicle. It will be equal to 1 iff the
/// route of the vehicle is not empty, 0 otherwise.
IntVar* ActiveVehicleVar(int vehicle) const {
return vehicle_active_[vehicle];
}

Also may need to add it to all VRP samples:

ls *{v,V}rp*     
cvrp_disjoint_tw.cc	   cvrptw_with_refueling_test.sh		 vrp_breaks.py      vrp_global_span.cc       vrp_nodes_indices.py	  vrp_pickup_delivery_lifo.py	vrp_solution_callback.py	 vrptw_store_solution_data.cc
cvrp_disjoint_tw_test.sh    cvrptw_with_resources.cc			 vrp_capacity.cc    VrpGlobalSpan.cs	     vrp_pickup_delivery.cc	  vrp_pickup_delivery.py	vrp_starts_ends.cc		 vrptw_store_solution_data.py
cvrp_reload.py		   cvrptw_with_resources_test.sh		 VrpCapacity.cs     VrpGlobalSpan.java       VrpPickupDelivery.cs	  vrp.py			VrpStartsEnds.cs		 vrp_with_time_limit.cc
cvrptw_break.py		   cvrptw_with_stop_times_and_resources.cc	 VrpCapacity.java   vrp_global_span.py       vrp_pickup_delivery_fifo.cc  vrp_resources.cc		VrpStartsEnds.java		 VrpWithTimeLimit.cs
cvrptw.cc		   cvrptw_with_stop_times_and_resources_test.sh  vrp_capacity.py    vrp_initial_routes.cc    VrpPickupDeliveryFifo.cs	  VrpResources.cs		vrp_starts_ends.py		 VrpWithTimeLimit.java
cvrptw.py		   cvrptw_with_time_dependent_costs.cc		 vrp.cc	    VrpInitialRoutes.cs      VrpPickupDeliveryFifo.java   VrpResources.java		vrp_time_windows.cc		 vrp_with_time_limit.py
cvrptw_soft_capacity.cc     cvrptw_with_time_dependent_costs.sh		 Vrp.cs	    VrpInitialRoutes.java    vrp_pickup_delivery_fifo.py  vrp_resources.py		VrpTimeWindows.cs
cvrptw_test.sh		   vrp_breaks.cc				 vrp_drop_nodes.cc  vrp_initial_routes.py    VrpPickupDelivery.java	  vrp_routes.cc		VrpTimeWindows.java
cvrptw_with_breaks.cc	   VrpBreaks.cs				 VrpDropNodes.cs    vrp_items_to_deliver.py  vrp_pickup_delivery_lifo.cc  vrp_solution_callback.cc	vrp_time_windows_per_vehicles.py
cvrptw_with_precedences.cc  vrp_breaks_from_start.py			 VrpDropNodes.java  Vrp.java		     VrpPickupDeliveryLifo.cs	  VrpSolutionCallback.cs	vrp_time_windows.py
cvrptw_with_refueling.cc    VrpBreaks.java				 vrp_drop_nodes.py  vrp_node_max.py	     VrpPickupDeliveryLifo.java   VrpSolutionCallback.java	vrp_tokens.py

@arnabanimesh
Copy link
Contributor Author

@Mizux assignment.Value(routing.ActiveVehicleVar(vehicle_index)) is not working in Python (same issue happening with TransitVar). I am using routing.IsVehicleUsed(assignment,vehicle_index) instead.

@arnabanimesh
Copy link
Contributor Author

arnabanimesh commented Jan 27, 2025

@Mizux modified all the files except for the ones where sat solver was used.

@arnabanimesh arnabanimesh changed the title Inactive trucks should not be shown in the output of cvrp_reload.py e… Inactive trucks should not be shown in the output Jan 27, 2025
@lperron
Copy link
Collaborator

lperron commented Jan 28, 2025

Impressive!!!

Let me run the github actions before merging.

@arnabanimesh
Copy link
Contributor Author

Impressive!!!

Let me run the github actions before merging.

Thanks

@arnabanimesh
Copy link
Contributor Author

@lperron Now the github actions should run fine.

@lperron
Copy link
Collaborator

lperron commented Jan 28, 2025 via email

@lperron lperron merged commit 749899c into google:main Jan 28, 2025
1 check passed
@arnabanimesh arnabanimesh deleted the patch-2 branch January 28, 2025 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Missing Feature/Wrapper Lang: Python Python wrapper issue Solver: Routing Uses the Routing library and the original CP solver
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants