【问题标题】:Get best feasible solution found after time limit - Pulp在时间限制后找到最佳可行解决方案 - 纸浆
【发布时间】:2019-07-28 14:11:19
【问题描述】:

我正在尝试解决具有 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

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

【问题讨论】:

  • 看来我的约束是错误的。解决了这个问题也解决了给我一个不可行的解决方案的问题!
  • 您可能想要添加您的答案/解决方案,然后接受它,让人们知道这不再是一个悬而未决的问题。

标签: python linear-programming pulp coin-or-cbc


【解决方案1】:

没有 subtours 的 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   

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-21
    • 1970-01-01
    相关资源
    最近更新 更多