Google ortools CVRP - 不同车辆的距离矩阵
Google ortools CVRP - different distance matrix by vehicle
在 ortools 中,我知道您可以 运行 CVRP 每辆车具有不同的容量。但是,您可以根据车辆传递不同的距离矩阵吗?例如,两个城市可能相距 1000 英里,但乘飞机到达那里可能比乘汽车快得多,因此在进行 CVRP 工作时我可能希望传递一个时间矩阵,而不是实际的距离矩阵。该时间矩阵会根据车辆类型而有所不同。
您可以通过 vector/list 个评估者。
这是C++ API/
应该接近这个:
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')
在 ortools 中,我知道您可以 运行 CVRP 每辆车具有不同的容量。但是,您可以根据车辆传递不同的距离矩阵吗?例如,两个城市可能相距 1000 英里,但乘飞机到达那里可能比乘汽车快得多,因此在进行 CVRP 工作时我可能希望传递一个时间矩阵,而不是实际的距离矩阵。该时间矩阵会根据车辆类型而有所不同。
您可以通过 vector/list 个评估者。
这是C++ API/
应该接近这个:
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')