我正在编写一个带有以下形式约束条件的pyomo整数规划:
def example_rule(model, j, t):
value = sum(model.x[j,i]*(util[i][t]) for i in model.F)
return 0 <= value <= 1
model.onelateral = Constraint(model.L, model.T, rule=example_rule)
util[i][t]
是一个包含值始终为0或1的字典。
model.x[j,i]
是二进制决策变量。
有时候当我运行我的模型时,它可以正常工作。然而,有时候当我更改util[i][t]
中的尺寸/值时,会出现以下错误:
ERROR: Constructing component 'example' from data=None failed:
ValueError: Invalid constraint expression. The constraint expression resolved to a trivial Boolean (True) instead of a Pyomo object. Please modify your rule to return Constraint.Feasible instead of True.
Error thrown for Constraint 'example[L01]'
我无法找到它为什么决定不喜欢util[i][t]
的输入值的任何一致性。里面从来没有空值。
如果我在没有这个限制的情况下运行模型,它就一直正常工作。
我还尝试以以下形式编写约束:
def example_rule(model,j):
a = 0
for t in model.T:
n = 0
for i in model.F:
if model.x[j,i].value == 1:
a = model.x[j,i] * util[i][t]
if a == 1:
n = n + a
return 0 <= n <= 1
model.example = Constraint(model.L, rule=example_rule)
但我收到了相同的错误信息。
我在这里查看过:https://groups.google.com/forum/#!msg/pyomo-forum/hZXDf7xGnTI/_aiAUN5IwgQJ,但这没有帮助我。
我已尝试使用cbc和glpk求解器。我正在使用Pyomo V5.2,Python V3.6.1。
提前感谢您的帮助。