我的模型中有多个级别的索引,pyomo
我需要能够像这样索引变量:
model.b['a',1]
但这似乎由于某种原因是不可能的。我可以像这样使用多级索引:
model = ConcreteModel()
model.W = RangeSet(0,1)
model.I = RangeSet(0,4)
model.J = RangeSet(0,4)
model.K = RangeSet(0,3)
model.B = Var(model.W, model.I, model.J, model.K)
model.B[1,2,3,0] # access the variable using the indices - THIS WORKS!!
但这不起作用,但是:
model = ConcreteModel()
model.W = Set(['a','b'])
model.I = RangeSet(0,4)
model.b = Var(model.W, model.I) # I can't even create this - throws exception
...它抛出异常:
TypeError: Cannot index a component with an indexed set
为什么第一个有效,第二个无效?