具有冗余约束的不可行解 - PuLP 和 COIN-OR

Infeasible solution with redundant constraints - PuLP and COIN-OR

我在 python 中使用 LP 模型使用 PuLPCBC。该模型有很多约束条件,当然其中很多都是多余的。我将展示一个例子。

#import libraries
from pulp import LpVariable, LpProblem, LpMaximize, lpSum, LpConstraint, LpStatus, value

prob = LpProblem("test_model", LpMaximize)
set_pt=[i for i in range(100)] #set of var
var = LpVariable.dicts("var",set_pt,lowBound=0,cat='Continuous')

# The objective function is added to 'prob' first
prob += lpSum([var[i] for i in set_pt]), "f(v)"

#constraits
for i in set_pt:
     prob += LpConstraint(var[i] <= 300000), "max margin "+str(i) 
     prob += LpConstraint(var[i] <= 30000000000), "ma2 margin "+str(i) 

#solve
prob.writeLP("price_mod2.lp")
print 'solver begin'
prob.solve()

# The status of the solution is printed to the screen
print "Status:", LpStatus[prob.status]

结果是:

solver begin
Status: Infeasible

当然,在这个例子中,两个约束显然都是多余的,而在我要解决的问题中,看到 的约束是多余的。

我不知道问题是否出在求解器 (CBC) 上,所以我可以使用 CPLEX 来解决冗余约束的问题,或者问题是 PuLP 并且我需要使用另一个库。或者,也许我需要对问题建模以使其具有冗余证明。

有什么指导吗? 谢谢!

编辑: 我尝试使用 CBC 打开解算器(在 excel 中)并且成功了,所以我认为这一定是PuLP 中的实现,或者我做错了什么,或者可能无法在 PuLP

中添加冗余约束

我没怎么用过 pulp,所以我不能在这里解释内部结构(这会让你的案例失败),但是 你以错误的方式使用了 pulp 的约束机制.

你的方法(失败):

for i in set_pt:
    prob += LpConstraint(var[i] <= 300000), "max margin "+str(i) 
    prob += LpConstraint(var[i] <= 30000000000), "ma2 margin "+str(i) 

工作备选方案 A(使用重载运算符)

for i in set_pt:
    prob += var[i] <= 300000, "max margin "+str(i)
    prob += var[i] <= 30000000000, "ma2 margin "+str(i)

可行的备选方案 B(显式使用 LpConstraint;需要导入)

for i in set_pt:
    prob += LpConstraint(var[i], LpConstraintLE, 300000), "max margin "+str(i)
    prob += LpConstraint(var[i], LpConstraintLE, 30000000000), "ma2 margin "+str(i)

后者更像是您最初的方法。但是您的用法看起来不像函数期望的那样(参见 docs