如果我有这样的限制阅读:
For all a in A there exists a b in B so that for all c in C it holds
that a variable x(a, b + c) is equal to a parameter m(a, c)短:
forall a in A, exists b in B, forall c in C: x(a,b+c)=m(a,c)我试图按以下方式创建约束:
constr = lambda model, a: any(all(model.x[a, b + c] <= model.m[a, c] for c in model.C[a]) for b in model.B if b + max(model.C[a]) <= max(model.B))
model.Constr = pyo.Constraint(model.A, rule = constr))变量和参数遵循How to define in pyomo parameters representing differently sized vectors and sets?:
model.m[a, c]的构造如m.data中所示,但二进制valuesmodel.A对应于以键为整数的m.nodes ( some_vector)model.B is pyo.Set(initialize=list(range(1000)))model.C的键对应于m.elementsmodel.x is pyo.Var(model.A, model.B, domain = pyo.Binary))。
目前,我收到以下错误:
ERROR: evaluating object as numeric value: x[0,0]
(object: <class 'pyomo.core.base.var._GeneralVarData'>)
No value for uninitialized NumericValue object x[0,0]
ERROR: Rule failed when generating expression for constraint Constr2 with
index 0: ValueError: No value for uninitialized NumericValue object x[0,0]
ERROR: Constructing component 'Constr2' from data=None failed: ValueError: No
value for uninitialized NumericValue object x[0,0]
Traceback (most recent call last):
File "gadget_chain.py", line 134, in <module>
op.satisfiability_check(mgcm)
File "optimise_payload.py", line 70, in satisfiability_check
model.Constr2 = pyo.Constraint(model.Nodes, rule = constr2)
File "/usr/lib/python3.10/site-packages/pyomo/core/base/block.py", line 544, in __setattr__
self.add_component(name, val)
File "/usr/lib/python3.10/site-packages/pyomo/core/base/block.py", line 1089, in add_component
val.construct(data)
File "/usr/lib/python3.10/site-packages/pyomo/core/base/constraint.py", line 836, in construct
index, self.rule(block, index)
File "/usr/lib/python3.10/site-packages/pyomo/core/base/util.py", line 304, in __call__
return self._fcn(parent, idx)
File "optimise_payload.py", line 69, in <lambda>
any(all(model.x[node, addr + reg] == model.NodeRegisterUsage[node, reg] for reg in model.RegisterIndices[node]) for addr in model.Payload if addr + max(model.RegisterIndices[node]) <= max(model.Payload))
File "optimise_payload.py", line 69, in <genexpr>
any(all(model.x[node, addr + reg] == model.NodeRegisterUsage[node, reg] for reg in model.RegisterIndices[node]) for addr in model.Payload if addr + max(model.RegisterIndices[node]) <= max(model.Payload))
File "pyomo/core/expr/logical_expr.pyx", line 304, in pyomo.core.expr.logical_expr.EqualityExpression.__nonzero__
File "pyomo/core/expr/numeric_expr.pyx", line 218, in pyomo.core.expr.numeric_expr.ExpressionBase.__call__
File "/usr/lib/python3.10/site-packages/pyomo/core/expr/visitor.py", line 1054, in evaluate_expression
return visitor.dfs_postorder_stack(exp)
File "/usr/lib/python3.10/site-packages/pyomo/core/expr/visitor.py", line 584, in dfs_postorder_stack
flag, value = self.visiting_potential_leaf(_sub)
File "/usr/lib/python3.10/site-packages/pyomo/core/expr/visitor.py", line 962, in visiting_potential_leaf
return True, value(node)
File "pyomo/core/expr/numvalue.pyx", line 246, in pyomo.core.expr.numvalue.value
File "pyomo/core/expr/numvalue.pyx", line 233, in pyomo.core.expr.numvalue.value
ValueError: No value for uninitialized NumericValue object x[0,0]参数在这里的命名方式不同。我检查了相互独立的约束,无论我是否评论其他的,错误都保持不变。因此,错误必须与此约束相对应。
通常,您也可以建议在Pyomo中创建约束的更有效的方法。我完全是这个软件的初学者。
发布于 2022-06-22 18:00:09
forall a in A, exists b in B, forall c in C: x(a,b+c)=m(a,c)我们错过了很多细节,我对你的非标准描述有点困惑,但我猜你的意思是:
x[a,1+c] = m[a,c] or x[a,2+c] = m[a,c] or ... ∀a,c对于最后一个c来说,这没有任何意义。所以不确定你想做什么。
这些or条件可以用Pyomo中的析取或使用二进制或SOS1变量来处理。
https://stackoverflow.com/questions/72717047
复制相似问题