Equal pickup and delivery constraint for every vehicle tour

25 views
Skip to first unread message

Sirine Belguith

unread,
Jul 24, 2024, 1:29:58 AM (yesterday) Jul 24
to or-tools...@googlegroups.com
Hello everyone !
I'm solving the VRPTW problem with pickup and delivery.   Each vehicle is capable of doing delivery, pickup, or both at once.
     # Add Pickup and Delivery constraints.
for node_index in range(1, len(data['pickup'])):
    if data['pickup'][node_index] > 0 or data['deliveries'][node_index] > 0:
        pickup_index = manager.NodeToIndex(node_index)
        delivery_index = manager.NodeToIndex(node_index)
        # Add Pickup and Delivery constraints.
        routing.AddPickupAndDelivery(pickup_index, delivery_index)
        routing.solver().Add(routing.VehicleVar(pickup_index) == routing.VehicleVar(delivery_index))
        routing.solver().Add(time_dimension.CumulVar(pickup_index) <= time_dimension.CumulVar(delivery_index))

What is the constraint that ensures equal pickup and delivery for each trip and that every pickup has a delivery for every vehicle tour? 

Do you have any ideas to help me?

Thanks in advance

Syrine

Sirine Belguith

unread,
Jul 24, 2024, 5:34:13 AM (yesterday) Jul 24
to or-tools...@googlegroups.com
Hello, 
  Why is this constraint not working?
# Add the constraint to ensure each pickup has a delivery.
for vehicle_id in range(int(data['num_vehicles'])):
    pickup_vars = []
    delivery_vars = []
    for i in range(len(data['demands'])):
        if data['demands'][i] > 0:
            pickup_vars.append(manager.NodeToIndex(i))
        if data['deliveries'][i] > 0:
            delivery_vars.append(manager.NodeToIndex(i))
    # Ensure the number of pickups is equal to the number of deliveries
    routing.solver().Add(sum([routing.ActiveVar(pickup_var) for pickup_var in pickup_vars]) == sum([routing.ActiveVar(delivery_var) for delivery_var in delivery_vars]))

thanks  
Reply all
Reply to author
Forward
0 new messages