1

I'm looking for a solution for VRPTW using google or- tools with vehicle working hours.

given any vehicle has it's own working hours. example: Vehicle A: 9am to 3pm Vehicle B: 8am to 4pm

I came up with below code

# times in seconds
data['working_time'] = [
  (0, 600), 
  (0, 32400), 
  (0, 36000)
]


# add working times for each vehicle
    for vehicle in range(duration_manager.GetNumberOfVehicles()):
        start_index = duration_routing.Start(vehicle)
        end_index = duration_routing.End(vehicle)

        duration_dimension.CumulVar(start_index).SetRange(
            data['working_time'][vehicle][0], data['working_time'][vehicle][1])
        duration_dimension.CumulVar(end_index).SetRange(
            data['working_time'][vehicle][0], data['working_time'][vehicle][1])

        duration_routing.solver().Add(duration_dimension.CumulVar(end_index) - duration_dimension.CumulVar(start_index) <= duration_dimension.CumulVar(end_index))

this works fine but if I changed

data['working_time'] = [
  (0, 600), 
  (0, 32400), 
  (3600, 36000) # start time change!!!
]

I'm getting

Exception: CP Solver fail

Please help

  • when invoking AddDimensionWithVehicleCapacity, use fix_start_cumul_to_zero=False (it's the 4th parameter). also you can use the vehicle_capacities parameter to set the end of shift values (3rd parameter). as for the shift start, I advice you to use SetMin instead of SetRange – Carpet4 Jul 25 '22 at 11:19
  • I need to assign different working times for each vehicle. can I do that with your suggestion? – Lahiru Supun Jul 25 '22 at 13:49
  • yes, vehicle_capacities is an array with the same length as the number of vehicles. – Carpet4 Jul 25 '22 at 14:05

0 Answers0