我想相对于索引为stop_index2
的另一个停靠点的到达时间来约束索引为stop_index1
的停靠点的到达时间。应根据直接行驶时间direct
和de回系数detour
来定义约束条件:
在Python中(不包括时间时间维度的创建):
n_stops = 11
n_vehicles = 3
ix_depot = 0
index_manager = pywrapcp.RoutingIndexManager(n_stops, n_vehicles, ix_depot)
routing_model = pywrapcp.RoutingModel(index_manager)
cpsolver = routing_model.solver()
ix1 = index_manager.NodeToIndex(1)
ix2 = index_manager.NodeToIndex(2)
factor = 0.8
direct = 1000
cpsolver.Add(time_dimension.CumulVar(ix2) < int(time_dimension.CumulVar(ix1) + factor * direct))
assignment = routing_model.Solve()
print(assignment.Value(routing_model.VehicleVar(stop_index)))
这是推荐的方法吗?