我正在尝试解决具有 10 个客户和 5 个站点的多站点车辆路线问题。添加 subtour 约束时,求解器不再在合理的时间内找到最优解。当我在一定时间后停止求解器并检索最佳解决方案时,他返回一个不可行的解决方案(连续变量,而需要整数)。我如何才能找到迄今为止找到的最佳可行解决方案,或者是否有其他方法可以解决我的问题?我知道堆栈上有一个类似的问题,但它解决了 gurobi 求解器的问题。
在这里你可以找到部分代码和他在 10 秒后给我的输出。
# Definition of the route variables:
route_vars = plp.LpVariable.dicts("Route",(Places,Places,Trucks),0,None,plp.LpInteger)
# constraint 7: No subtours
for i in Places:
for j in Places:
for k in Trucks:
if i != j:
prob += u[i]-u[j] + (15)*route_vars[i][j][k] <= 14
# Solve the problem
prob.solve(plp.PULP_CBC_CMD(maxSeconds=10))
print("status:", plp.LpStatus[prob.status])
print("optimal solution to the problem: ", plp.value(prob.objective))
# Print Results
for i in Places:
for k in Trucks:
for j in Places:
if plp.value(route_vars[i][j][k]) != 0:
print(plp.value(route_vars[i][j][k]), 'Truck ',k + 1, " from Place ",i+1, " to place ",j+1)
运行10秒后输出:
status: Not Solved
optimal solution to the problem: 348.1102769976801
0.066666667 Truck 7 from Place 1 to place 11
0.93333333 Truck 8 from Place 1 to place 11
0.066666667 Truck 4 from Place 2 to place 6
0.93333333 Truck 7 from Place 2 to place 6
0.066666667 Truck 2 from Place 3 to place 7
0.93333333 Truck 8 from Place 3 to place 7
0.93333333 Truck 1 from Place 4 to place 5
0.033333333 Truck 3 from Place 4 to place 5
0.033333333 Truck 3 from Place 4 to place 9
0.93333333 Truck 1 from Place 5 to place 9
0.033333333 Truck 3 from Place 5 to place 4
0.033333333 Truck 4 from Place 5 to place 9
0.066666667 Truck 4 from Place 6 to place 2
0.93333333 Truck 7 from Place 6 to place 2
0.066666667 Truck 2 from Place 7 to place 3
0.93333333 Truck 8 from Place 7 to place 3
0.066666667 Truck 2 from Place 8 to place 10
0.93333333 Truck 8 from Place 8 to place 10
0.93333333 Truck 1 from Place 9 to place 4
0.033333333 Truck 3 from Place 9 to place 4
0.033333333 Truck 4 from Place 9 to place 5
0.066666667 Truck 2 from Place 10 to place 8
0.93333333 Truck 8 from Place 10 to place 8
0.066666667 Truck 7 from Place 11 to place 1
0.93333333 Truck 8 from Place 11 to place 1
如您所见,它给了我一个不可行的解决方案。