I went through the Vehicle Routing Problem example and was able to replicate it. On the example, there is a constraint added for vehicle maximum distance as shown below:

dimension_name = 'Distance'
    0,  # no slack
    3000,  # vehicle maximum travel distance
    True,  # start cumul to zero
distance_dimension = routing.GetDimensionOrDie(dimension_name)

Similar to the CVRP, how do I modify the constraint for the number of locations that each vehicle can visit (either global or by each vehicle) rather than the demand?


1 Answer 1


Crossposted from: Stack Overflow

The idea is to create another dimension ('visit') that is incremented by 1 on each visit. Then use SetCumulVarSoftUpperBound on the cumul variable of that dimension at the end of each route.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.