PULP MILP如何验证“最佳”状态?

时间:2019-12-09 03:31:29

标签: python optimization linear-programming pulp

我在python中使用PULP包来解决混合整数线性编程问题。解决问题后,我可以打印出以下内容:

print(“状态:”,LpStatus [prob.status]),它返回“最佳”,“可行”或“不可行”状态。

我的问题是,当返回最佳状态时,Pulp软件包如何验证其达到最佳解决方案?

更新:我已经为我的问题提供了一个具体示例。

import itertools
import pulp

distances = {(0,1): 1.0, (0,2): 2.0, (1,2): 3.0, (0,3): 33.0, (1,3): 34.0, (2,3): 23.0} ## distances of connecting islands together and islands to terminal

x = pulp.LpVariable.dicts("x", distances.keys(), lowBound=0, upBound=1)

mod = pulp.LpProblem("Islands", pulp.LpMinimize)

y = pulp.LpVariable("y", lowBound=0, upBound = sum(distances.values()))
y = sum([distances[k] * x[k] for k in distances])
# Objective
mod += y

## constraint that there has to be at least 3 connections in the system:
mod += sum(x[edge] for edge in distances)  >= 3 

# Solve and output
mod.solve()

## printing the solutions: 

print (pulp.LpStatus[mod.status], y.value())

for edge in distances:
    print (edge, x[edge].value())

0 个答案:

没有答案