Problem with Implementing Soft Capacity Constraint in VRP with Pickup and Delivery

58 views
Skip to first unread message

Adam Brejtfus

unread,
Jul 12, 2024, 8:14:31 AM (14 days ago) Jul 12
to or-tools-discuss

Hi,

I am trying to solve a Vehicle Routing Problem (VRP) with pickup and delivery constraints and a capacity constraint. Specifically, I want to implement a soft upper bound on the capacity, which penalizes the vehicle if it attempts to pick up more than the available capacity.

Here is my code:

routing.AddDimensionWithVehicleCapacity(
            capacity_callback_index,
            0,
            hard_capacity_limits,
            True,
            "Capacity",
        )
        capacity_dimension = routing.GetDimensionOrDie("Capacity")
        soft_limit = 20
        penalty = 1000
        for node in pickup_nodes:
            index = index_manager.NodeToIndex(node)

            capacity_dimension.SetCumulVarSoftUpperBound(index, soft_limit, penalty)

Unfortunately, this approach doesn't work as intended. The soft upper bound is checked before the pickup. This allows the vehicle to break the capacity constraint without incurring a penalty. For example, if the capacity limit is 20 before a pickup and a node requires a pickup of 10, the vehicle's current load may be 19. After this pickup, the vehicle's load would be 29, exceeding the limit by 9, but the penalty is not applied.

Could you provide guidance on how to correctly implement this constraint so that the penalty is applied when the vehicle's capacity is exceeded after the pickup?

Reply all
Reply to author
Forward
0 new messages