How to limit the number of locations for delivery by a single truck


I have a problem with delivery routes which should not consists of more then say 4 locations (addresses). This constrained is being imposed by the transportation company (outsourced service) which imposes an additional fee (kind of a fine) for every additional (above limit) delivery point. So we would like to keep the maximum locations for a single truck which does not get fined.
Thinking about the solution we cannot directly use orders as there are usually a few orders for any given address to be delivered.
Any ideas how to implement such location maximum visit constrained?

Hi @Grzegorz ,

Firstly you need a state updater to memorize the number of locations each route visits. Then you need a route constraint to disallow an insertion if the route already visits N locations (the limit) and the job introduces a new one. Whether the constraint is a hard one or a soft one depends on your need.

Hopefully the above helps.

Best regards,


It will be good, if you define capacity or capacity-demand for your vehicle. If the define capacity=4 as vehicleType, then vehicle can cater maximum 4 addresses only.

@mourya09 This is not true. A vehicle with capacity 4 could do an unlimited number of jobs, provided that there are not 4 deliveries on the vehicle at any one time. Nothing stops the vehicle doing a delivery, doing a pickup (to go back to 4 items on board) and then going and delivering all of those items.

Did you solve this problem? can you share your solution? Thanks