我已经使用Google OR-Tools建模了PDPTW。
我为我的每辆车定义了一个“成本维度”,如下所示:
for vehicle_idx in range(data['n_vehicles']):
def vehicle_cost_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]
cost_callback_index = routing.RegisterTransitCallback(vehicle_cost_callback)
cost_callback_indices.append(cost_callback_index)
routing.SetArcCostEvaluatorOfVehicle(cost_callback_index, vehicle_idx)
# cost dimension
cost_dimension_name = 'Cost'
routing.AddDimensionWithVehicleTransits(
cost_callback_indices,
0,
max_int,
False,
cost_dimension_name)
现在,我想对给定车辆子集的总成本(总和)设置一个约束。有人告诉我here收集车辆费用累计变量,并对这些变量添加约束。 到目前为止,我的尝试(失败)是:
total_cost = []
for i in range(data['n_vehicles']):
if some_selection_condition:
total_cost.append(cost_dimension.CumulVar(routing.End(i)))
routing.solver().Add(routing.solver().Sum(total_cost) <= cost_max)
这似乎是不正确的,因为即使我设置了很大的cost_max
,但我肯定已经存在求解器,但求解器状态= 2(不可行)。我在做什么错了?