VRP: enable different distance limit for different types of vehicle

342 views
Skip to first unread message

Mr.Pickle

unread,
Aug 20, 2021, 5:03:00 PM8/20/21
to or-tools-discuss

How to set differnt max driving distance for different types of vehicle?
e.g. If I have large, medium, and small vehicles, I want to set max of 180km for small vehicle, 210km for medium vehicle, and 250 for large vehicle.

previously, the max driving distance limit is set all the same via below function:

def add_distance_dimension(routing, transit_callback_index, data, manager):
"""Add Global Span constraint"""
   distance = "Distance"
   maximum_distance = 280
   routing.AddDimension(
   transit_callback_index,
   0, # null slack
   maximum_distance, # maximum distance per vehicle
   True, # start cumul to zero
   distance)

blind.line

unread,
Aug 20, 2021, 8:03:47 PM8/20/21
to or-tools...@googlegroups.com
Use the version that accepts a vector of capacities, one per vehicle:



James

On Aug 20, 2021, at 14:03, Mr.Pickle <westli...@gmail.com> wrote:


--
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/6c6c774c-7967-446e-9583-4011259c8552n%40googlegroups.com.

Mr.Pickle

unread,
Aug 21, 2021, 7:02:38 AM8/21/21
to or-tools-discuss
Please note my question is not about define different vehicle capacity, but the max distance limit for different vehicle. Do you mean in above code, I should change  routing.AddDimension to routing. AddDimensionWithVehicleCapacity?

def add_distance_dimension(routingtransit_callback_indexdatamanager):
"""Add Global Span constraint"""
   distance "Distance"
   maximum_distance 280
  # routing.AddDimension(        
   routing. AddDimensionWithVehicleCapacity (

   transit_callback_index,
   0# null slack
   maximum_distance# maximum distance per vehicle
   True# start cumul to zero
   distance)  


blind.line

unread,
Aug 22, 2021, 11:49:42 AM8/22/21
to or-tools...@googlegroups.com
A dimension is a dimension, capacity is just the max of the dimension. No matter if you call the dimension time or distance or cakes. 

What I said was to use the version of the API call creating a dimension that takes a *vector* of values, one per vehicle, to define each vehicles’ maximum value for that dimension. Do read carefully the API call I linked to in the previous reply. 

So your function also needs to add 

max_dist = [200, 200, 100, 280, …, 100]

James

On Aug 21, 2021, at 04:02, Mr.Pickle <westli...@gmail.com> wrote:

Please note my question is not about define different vehicle capacity, but the max distance limit for different vehicle. Do you mean in above code, I should change  routing.AddDimension to routing. AddDimensionWithVehicleCapacity?

Mr.Pickle

unread,
Aug 22, 2021, 2:23:48 PM8/22/21
to or-tools-discuss
thanks. worked well

juan jose galvan

unread,
Sep 24, 2021, 8:23:28 PM9/24/21
to or-tools-discuss
Hi, could you share your code??
I tryed to add this dimension and do not work.

Mizux Seiha

unread,
Sep 25, 2021, 4:27:31 AM9/25/21
to or-tools-discuss
This gist: vrp_multiple_transit.py
https://gist.github.com/Mizux/6d9283388150020df7542adf63577786 line 76...
Reply all
Reply to author
Forward
0 new messages