简体   繁体   English

不同车速的车辆路线(谷歌或工具)

[英]Vehicle Routing with Different Vehicle Speed (Google OR Tools)

Currently, I am working on the vehicle routing problems with different vehicle speeds.目前,我正在研究不同车速的车辆路线问题。 My approach is using speed adjustment ratio for each vehicle (which mean I have default speed), to build the time constraint I used the code: ( data['travel_service'] is time matrix + service time and data['travel_service'] is service time only)我的方法是使用每辆车的速度调整率(这意味着我有默认速度),来构建我使用代码的时间约束:( data['travel_service']是时间矩阵 + 服务时间和data['travel_service']是仅服务时间)

data['vehicle_speed_adjustment'] = [1.5, 1.3, 1.2, 1]
def create_vehicle_travel_service_time_callback(travel_service_matrix, service_time, speed_adjust_ratio):
    def time_callback(from_index, to_index):
        """Returns the travel time between the two nodes + the service time of starting node."""
        # Convert from routing variable Index to time matrix NodeIndex.
        from_node = manager.IndexToNode(from_index)
        to_node = manager.IndexToNode(to_index)
        if travel_service_matrix[from_node][to_node] == sys.maxsize or travel_service_matrix[from_node][to_node] == service_time[from_node]:
            return travel_service_matrix[from_node][to_node]
        else:
            return int((travel_service_matrix[from_node][to_node]-service_time[from_node])/speed_adjust_ratio) + service_time[from_node]
    return time_callback

# time_callback_index = []
for vehicle_id in range(data['num_vehicles']):
    time_callback = create_vehicle_travel_service_time_callback(data['travel_service'], data['service_time'], data['vehicle_speed_adjustment'][vehicle_id])
    time_callback_index = routing.RegisterTransitCallback(time_callback)
    print(time_callback_index)
    routing.AddDimension(
        time_callback_index,
        max_waiting_time,  # allow waiting time
        max_operation_time,  # maximum time per vehicle
        False,  
        'Time')
    
time_dimension = routing.GetDimensionOrDie('Time')

The problem is, when I try to run the program, the program only recognize the first value of the data['vehicle_speed_adjustment'] list which is 1.5 and applied it into every vehicle.问题是,当我尝试运行该程序时,该程序仅识别data['vehicle_speed_adjustment']列表的第一个值为 1.5 并将其应用于每辆车。

Can someone explain why this happens?有人可以解释为什么会这样吗?

data['travel_service'] = [[0, 4, 22, 21, 48, 28, 8, 23, 16, 14, 23, 37], [59, 0, 79, 78, 104, 84, 63, 76, 68, 66, 78, 91], [32, 34, 0, 12, 38, 32, 31, 14, 41, 40, 41, 52], [27, 29, 8, 0, 35, 28, 27, 11, 36, 35, 37, 47], [58, 59, 38, 39, 0, 39, 52, 41, 62, 61, 60, 60], [36, 37, 30, 30, 37, 0, 32, 30, 41, 40, 39, 34], [18, 18, 31, 31, 52, 34, 0, 32, 20, 19, 22, 39], [33, 31, 14, 15, 41, 32, 32, 0, 42, 41, 43, 54], [44, 41, 59, 58, 80, 61, 38, 60, 0, 31, 36, 53], [69, 66, 85, 84, 106, 87, 64, 86, 58, 0, 65, 83], [33, 33, 41, 41, 60, 41, 22, 43, 18, 20, 0, 31], [45, 44, 50, 49, 58, 34, 37, 52, 33, 36, 29, 0]]

data['travel_service'] = [0, 55, 10, 6, 10, 8, 10, 10, 28, 55, 10, 8]

data['num_vehicles'] = 4

nearly good, you just need to create an array of callback index then pass the array to AddDimension...几乎很好,您只需要创建一个回调索引数组,然后将该数组传递给 AddDimension ...
note: array length MUST be equal to the vehicle number.注意:数组长度必须等于车辆编号。 note2: you can reuse the same registered callback index for few vehicles eg you have two bike, and three car in this order you could pass an array [1, 1, 2, 2, 2] supposing RegisterTransitCallback returned 1 and 2 ...注意2:您可以为少数车辆重用相同的注册回调索引,例如您有两辆自行车,三辆汽车按此顺序您可以传递数组[1, 1, 2, 2, 2]假设 RegisterTransitCallback 返回12 ...

ref: https://github.com/google/or-tools/blob/45770b833997f827d322e929b1ed4781c4e60d44/ortools/constraint_solver/routing.h#L416-L418参考: https://github.com/google/or-tools/blob/45770b833997f827d322e929b1ed4781c4e60d44/ortools/constraint_solver/routing.h#L416-L418

time_callback_indices = []
for vehicle_id in range(data['num_vehicles']):
    time_callback = create_vehicle_travel_service_time_callback(data['travel_service'], data['service_time'], data['vehicle_speed_adjustment'][vehicle_id])
    time_callback_indices.append(routing.RegisterTransitCallback(time_callback))
    #print(time_callback_index)

routing.AddDimensionWithVehicleTransits(
    time_callback_indices,
    max_waiting_time,  # allow waiting time
    max_operation_time,  # maximum time per vehicle
    False,  
    'Time')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Google OR 工具解决车辆路径问题 (CVRPTW) 所需的时间取决于车辆容量的排序 - Time taken to solve a Vehicle Routing Problem (CVRPTW) using Google OR Tools depends on the ordering of vehicle capacity 如何绘制谷歌或工具车辆路线问题解决方案? - How to graph Google OR Tools Vehicle Routing Problem Solution? Or-tools带有中断的Python车辆路由问题 - Or-tools Python Vehicle Routing Prob with Breaks 使用或工具的车辆路径中的最小距离约束 - minimum distance constraint in vehicle routing using or tools 在 Or 工具中设置距离维度以解决车辆路径问题 - Setting distance Dimension in Or tools for vehicle routing problem 如何让 Google OR 工具部署更多车辆 - How to make Google OR Tools Deploy More Vehicle 使用 or-tools 的不同车辆类型的 VRP - VRP with different vehicle types using or-tools 是否有针对此 Python/Google OR 车辆路由工具程序的简单修复,使其按预期工作? - Is there a simple fix for this Python/ Google OR tools program for Vehicle Routing to make it work as intended? 如何解释从 Google OR Tools 返回的 Vehicle Routing Problem 解决方案? - How do I interpret the Vehicle Routing Problem solution returned from Google OR Tools? 带有非连接图或工具 Python 的车辆路由问题 - Vehicle Routing Prob with non-connected graph or-tools Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM