Reputation: 1259
I'm trying to optimize the best routes VRP with OR-Tools. I couldn't find the right function in the documentation.
CASE: Some customers only accept pickup trucks, some accept only trucks, some accept both trucks, pickup, and vans. There's a single depot location and vehicles should carry orders to the right customers with accepted vehicles.
Those vehicles I have
Customers accept those vehicle types
These vehicles should be directed to the appropriate customers.
Do you have any thoughts or are there any or-tools function regarding this?
Upvotes: 2
Views: 1201
Reputation: 9291
You can use the RoutingModel::VehicleVar(index)
Pseudo code in Python (using customer_id as node_id)
# Vehicles list
trucks = [1, 3, 6, 7, 9, 10]
vans = [4, 5]
pickups = [2, 8]
# location list with a tuple (location, truck, van pickup)
locations = [
(1, True, True, True), # C-01
(2, True, True, False), # C-02
(3, True, False, False), # C-03
(4, True, True, True), # C-04
...
]
for location, truck_allowed, van_allowed, pickup_allowed in locations:
index = manager.NodeToIndex(location)
allowed_vehicles = [] # you can add -1 iff the location can be dropped
if truck_allowed:
allowed_vehicles.extend(trucks)
if van_allowed:
allowed_vehicles.extend(vans)
if pickup_allowed:
allowed_vehicles.extend(pickups)
routing.VehicleVar(index).SetValues(allowed_vehicles)
side note: solver vehicle ID start at 0 but here I followed you vehicle_id convention starting at 1...
Upvotes: 1