Google ortools CVRP不同车辆距离矩阵

2024-09-30 02:32:46 发布

您现在位置:Python中文网/ 问答频道 /正文

在ortools中,我知道您可以使用每辆车的不同容量运行CVRP。但是,能否根据车辆传递不同的距离矩阵?例如,两个城市可能相距1000英里,但坐飞机到那里可能比坐汽车快得多,因此在进行CVRP工作时,我可能希望通过一个时间矩阵,而不是实际的距离矩阵。该时间矩阵将根据车辆类型而有所不同


Tags: 距离类型时间矩阵汽车容量车辆ortools
2条回答

应该接近这一点:

callback_indices = []
for vehicle_idx in range(data['n_vehicles']):
    def vehicle_callback(from_index, to_index, i=vehicle_idx):
        from_node = manager.IndexToNode(from_index)
        to_node = manager.IndexToNode(to_index)
        return data['vehicle_costs'][i] * data['time_matrices'][i][from_node][to_node]
    callback_index = routing.RegisterTransitCallback(vehicle_callback)
    callback_indices.append(callback_index)


routing.AddDimensionWithVehicleTransits(
    callback_indices,
    0,
    max,
    False,
    'DimensionName')

您可以传递向量/评估器列表

这是C++ API/

相关问题 更多 >

    热门问题