How to add lunch break during time window using or-tools for Vehicle Routing Problem

39 views Asked by At

I am implementing Prize Collecting Vehicle Routing Problem using or-tools. I am trying to add a new constraint. I need to add a "lunch break" anywhere along the route. For example a 30 minute break during time window 11:00 to 15:00. I have only one vehicle of one type.

I could not find no python docs for this problem. This is my current Model.

managerer = pywrapcp.RoutingIndexManager(num_nodes, 1, DEPOT_INDEX) # 1 vehicle
routing = pywrapcp.RoutingModel(manager)

def time_callback(from_index, to_index): # transit (duration) callback
    return DURATION_MATRIX[manager.IndexToNode(from_index)][manager.IndexToNode(to_index)]


transit_callback_index = routing.RegisterTransitCallback(time_callback)
routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)

dimension_name = 'Time'
routing.AddDimension(
    transit_callback_index,
    60, # allow waiting time
    24 * 60,  # vehicle maximum travel time
    False,  # start cumul to zero
    dimension_name)
time_dimension = routing.GetDimensionOrDie(dimension_name)

# Add time window constraints
for location_idx, time_window in enumerate(TIME_WINDOWS):
    index = manager.NodeToIndex(location_idx)
    time_dimension.CumulVar(index).SetRange(time_window[0], time_window[1])  
    
# TODO add 30minute lunch break during time window (11:00, 15:00)

# Allow to drop nodes.
for node in range(0, num_nodes):
routing.AddDisjunction([manager.NodeToIndex(node)], VISIT_SCORES[node])

assignment = routing.SolveWithParameters(search_parameters)
0

There are 0 answers