我正在尝试编写一个 Pyomo 模型,其中我有一组变量,由 {1,2,...,N} 中的 aj 索引,并且对于每个 j,{1,...,N_j} 中的 ai。
我现在的代码是:
n0=28
n1=8
n2=8
n3=8
n4=10
N=[n0, n1, n2, n3, n4]
rN=range(5)
model = ConcreteModel()
model.J = [RangeSet(1,N[i]) for i in rN]
model.X = [Var(model.J[i], within=NonNegativeReals) for i in rN]
当我尝试访问变量时,出现错误:
>>>model.X[0][0]
Traceback (most recent call last):
File "<ipython-input-177-297a76d94388>", line 1, in <module>
model.X[0][0]
File "/path/anaconda3/lib/python3.7/site-
packages/pyomo/core/base/indexed_component.py", line 374, in __getitem__
self._not_constructed_error(index)
File "/path/anaconda3/lib/python3.7/site-
packages/pyomo/core/base/indexed_component.py", line 520, in _not_constructed_error
"not been constructed." % (self.name, idx_str,))
ValueError: Error retrieving component IndexedVar[1]: The component has not been constructed.
我认为错误可能是我无法在列表中写入变量,但我想不出任何其他解决方案。
明月笑刀无情
相关分类