【发布时间】:2019-02-20 18:57:58
【问题描述】:
我正在尝试通过以下方式在 Pyomo 中定义一组变量:
def initA ( i , model ):
for i in range(p)
yield -1
def initB ( i , model ):
for i in range(p)
yield random.randrage(-999999, 999999)
# variables
model.A = Set()
model.B = Set()
model.a = Var(model.A, within=IntegerSet, bounds=(-1,1), initialize=initA)
model.b = Var(model.B, domain=Reals, initialize=initB)
我使用 Pyomo 的打印功能来验证集合,我得到了这个:
a : Size=0, Index=A
Key : Lower : Value : Upper : Fixed : Stale : Domain
b : Size=0, Index=B
Key : Lower : Value : Upper : Fixed : Stale : Domain
当我尝试解决模型时收到此错误:
ERROR: Rule failed when generating expression for objective OBJ: KeyError:
"Index '1' is not valid for indexed component 'a'"
创建变量集时有什么遗漏吗?
【问题讨论】: