我正在尝试在Pyomo中运行此整数程序优化,并不断收到错误“ KeyError:“索引对于索引组件'x'无效。”我在下面附加了相关代码行,有人知道我怎么可能能够解决此错误?
model.x = pyo.Var(model.S, model.I, model.E, model.P, model.W, within=pyo.Binary)
def only_eligible_rule(model, i,e,p,w):
return sum(model.x[s,i,e,p,w] for s in model.EligStudent) <= 1
model.only_eligible_rule = pyo.Constraint(model.I, model.E, model.P, model.W, rule=only_eligible_rule)```