微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。