Google OR-Tools:带有时间窗口的VRP-解决方案不考虑运输时间

问题描述

在尝试使用时间窗(基于tutorial)求解VRP时,求解器似乎并未考虑运输时间。相反,它似乎假设您可以在节点之间即时跳转。为什么不应用time_dimension中的运输和装载/卸载时间?

Route for vehicle 6:
 Node A: Time(36000,36000) ->
 Node B: Time(36000,36000) ->
 Node C: Time(36000,36000) ->
 Node D: Time(36000,36000) ->
 Node A: Time(36000,36000)
Cost of the route: $811.84
Timing of route: 10:0:0 - 10:0:0
Duration on-duty: 0hr,0min,0sec

我已验证data['time_matrix']并非全为零。以下是用于上下文的大部分代码:

# Create and register a transit time callback.
def transit_time_callback(from_index,to_index):
    """Returns the travel time only between the two nodes."""
    # Convert from routing variable Index to time matrix NodeIndex.
    from_node = manager.IndexToNode(from_index)
    to_node = manager.IndexToNode(to_index)
    return data['time_matrix'][from_node][to_node]

# Create and register a time callback.
def time_callback(from_index,to_index):
    """Returns the travel and dock time between the two nodes."""
    # Convert from routing variable Index to time matrix NodeIndex.
    transit_time = transit_time_callback(from_index,to_index)
    if to_node in data['pickups']:
        dock_time = data['load_time'][to_node]
    else:
        dock_time = data['unload_time'][to_node]
    return transit_time + dock_time

time_callback_index = routing.RegisterTransitCallback(time_callback)

# Add time windows constraint.
routing.AddDimension(
    time_callback_index,4 * MIN_PER_HR * SEC_PER_MIN,# allow waiting time
    24 * MIN_PER_HR * SEC_PER_MIN,# maximum time per vehicle
    False,# Don't force start cumul to zero.
    'Time')
time_dimension = routing.GetDimensionOrDie('Time')

# Add time window constraints for each location.
for location_idx,time_window in enumerate(data['time_windows']):
    index = manager.NodeToIndex(location_idx)
    time_dimension.CumulVar(index).SetRange(time_window[0],time_window[1])

# Limit max on-duty time for each vehicle
for vehicle_id in range(data['num_vehicles']):
    routing.solver().Add(
        time_dimension.CumulVar(routing.End(vehicle_id)) - time_dimension.CumulVar(routing.Start(vehicle_id)) <= MAX_TIME_ON_DUTY)

# Minimize on-duty duration.
for i in range(data['num_vehicles']):
    routing.AddVariableMaximizedByFinalizer(
        time_dimension.CumulVar(routing.Start(i)))
    routing.AddVariableMinimizedByFinalizer(
        time_dimension.CumulVar(routing.End(i)))

# Set cost
routing.SetArcCostEvaluatorOfAllVehicles(time_callback_index)

# Solve the problem
search_parameters = pywrapcp.DefaultRoutingSearchParameters()
search_parameters.first_solution_strategy = (
    routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC)
solution = routing.SolveWithParameters(search_parameters)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...