在时间限制后找到最佳可行解决方案 - Pulp

Get best feasible solution found after time limit - Pulp

我正在尝试使用 解决一个包含 10 个客户和 5 个站点的多站点车辆路径问题。添加 subtour 约束时,求解器无法在合理的时间内找到最佳解决方案。当我在一定时间后停止求解器并检索最佳解决方案时,他 returns 一个不可行的解决方案(需要整数的连续变量)。我怎样才能找到迄今为止找到的最佳可行解决方案,或者是否有其他方法可以解决我的问题?我知道堆栈上有一个类似的问题,但它解决了 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

如您所见,它给了我一个不可行的解决方案。

没有子路线的 Miller-Tucker-Zemlin 约束定义错误。约束应该看起来像这样,其中 N 是客户数量,D 是站点数量。

# constraint 8: No subtours (Miller Tucker Zemlin)
for i in range(0,N):
    for j in range(0,N):
        for k in Trucks:
            if j != i:
                prob += u[i]-u[j] + (N+D+1)*route_vars[i][j][k] <= N+D