此示例在某种程度上也适用于(字符串)索引集吗? 就我而言,出现以下错误:
'IndexedSet'对象没有属性'next'
具有非索引集的工作示例:
m.s = Set(initialize=['A','B','C'], ordered=True) m.v = Var(m.s) def _c_rule(m, i): if i == 'A': return Constraint.Skip return m.v[i] <= m.v[m.s.prev(i)] m.c = Constraint(m.s, rule=_c_rule) # Or the opposite way def _c2_rule(m, i): if i == 'C': return Constraint.Skip return m.v[m.s.next(i)] <= m.v[i] m.c2 = Constraint(m.s, rule=_c2_rule)
不起作用:
model = ConcreteModel()
model.S = Set(("A", "B", "C"),initialize=("A", "B", "C"), ordered=True)
print(model.S.next(model.S["A"]))
如果没有,是否有解决方法?