VRP with different vehicle types using or-tools

Tags: , ,

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

enter image description here

Customers accept those vehicle types

enter image description here

These vehicles should be directed to the appropriate customers. 

Do you have any thoughts or are there any or-tools function regarding this?


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:
  if van_allowed:
  if pickup_allowed:

ref: https://github.com/google/or-tools/blob/b37d9c786b69128f3505f15beca09e89bf078a89/ortools/constraint_solver/routing.h#L1224-L1226

side note: solver vehicle ID start at 0 but here I followed you vehicle_id convention starting at 1…

Source: stackoverflow