我正在编写一个具有以下形式约束的 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)
Run Code Online (Sandbox Code Playgroud)
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]'
Run Code Online (Sandbox Code Playgroud)
我找不到任何一致性为什么它决定它不喜欢util[i][t]. 那里永远不会有任何空值。 …