VRP: is routing.AddDimensionWithVehicleCapacity auto maxmize both weight and space utilization?

496 views
Skip to first unread message

Mr.Pickle

unread,
Sep 18, 2021, 12:44:20 PM9/18/21
to or-tools-discuss
My model consiers both weight and space constaints, like below:

#weight constaint
def add_cm3_constraints(routing, data, demand_callback_index):
"""Adds capacity constraint"""
cm3 = "cm3"
routing.AddDimensionWithVehicleCapacity(
demand_callback_index,
0, # null capacity slack
cm3_vector(), # vector vehicle_capacity
True, # start cumul to zero
cm3)

#space constraint
def add_capacity_constraints(routing, data, demand_callback_index, manager):
"""Adds capacity constraint"""
capacity = "Capacity"
routing.AddDimensionWithVehicleCapacity(
demand_callback_index,
0, # null capacity slack
capacity_vector(), # vector vehicle_capacity
True, # start cumul to zero
capacity)

both constraints were using standard routing.AddDimensionWithVehicleCapacity. is such default setting auto maxmize both the weight and space utilization, i.e. to achieve the best combination of weight and light cargos loaded in a vehicle (meaning max profit)?

Kerem Aslan

unread,
Sep 20, 2021, 1:22:29 AM9/20/21
to or-tools-discuss
No, it doesn't automatically consider the best utilization of space. It just adds a constraint that will respect the vehicle capacity. Although, do note that these will result in two separate dimensions that won't be aware of each other, meaning, they won't add up. If you want to add this to the objective function, you can use SetGlobalSpanCostCoefficent:

Though, do note that the routing library works to minimize the objective function, so by definition it will try to minimize the space usage. Perhaps you can add a negative value to try to maximise it. I have never tried that, so I don't know it would work as intented.



Op zondag 19 september 2021 om 00:44:20 UTC+8 schreef westli...@gmail.com:

Mizux Seiha

unread,
Sep 20, 2021, 5:22:03 AM9/20/21
to or-tools-discuss
You should also use SetFixedOfVehicle() so solver will have incentive to limit the number of vehicles and use light cargo (if cheaper) to minimize the objective cost...

Mr.Pickle

unread,
Sep 20, 2021, 3:45:44 PM9/20/21
to or-tools-discuss
I guess I didn't make it clear. Besides weight constaints, which is a dimension, I also added the 2nd dimension "cubic meters". since the transportation market charges freight cost based on both weight and cubic meters, whichever is larger is used for calculating cost. So for a logistics company, the best case is that both space and weight (payload) of a truck is fully utilized  when assigning shipments.  i.e. a truck loading a lof of both heavy and light cargos together to enable the largest profits.

SetGlobalSpanCostCoefficent seems to target minizing the largest travel distance among vehicles. When I enable this function, it actually generated more vehicles and higer cost.

Kerem Aslan

unread,
Sep 20, 2021, 10:30:36 PM9/20/21
to or-tools-discuss
As far as I know, I  believe that setGlobalSpanCostCoeffcient or alternatively setSpanCostCoefficientForAllVehicles are really the only ways to add a dimension's values to the objective cost. Note that both functions are on a routing dimension, so you would need to set them on the appropriate dimension.
Op dinsdag 21 september 2021 om 03:45:44 UTC+8 schreef westli...@gmail.com:

Laurent Perron

unread,
Sep 21, 2021, 2:11:05 AM9/21/21
to or-tools-discuss
You can also add soft penalties on cumul vars. 

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/738e6713-2d65-4fb1-8244-6b46888cf319n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages