The problem is you are using string values in your Set (which is perfectly fine and something that Pyomo supports). However, when you iterate over the Set, you are getting strings, so you cannot directly “do math” on the set values. Instead, you should make use of the Set’s `ord()`, `next()`, and `prev()` methods.
I would do something similar to:
model.t = Set() # note that since Pyomo 5.6, Pyomo sets are ordered by insertion order unless otherwise specified
def MSBnew_rule(model, p, m, t):
return model.DURV[p, m, t] == sum(
model.INM[p, m, model.t.prev(tt)] - model.OUTM[p, m, tt]
for tt in model.t if model.t.ord(tt) <= model.t.ord(t)
) + model.OUTM[p, m, t]
model.MSBnew = Constraint(model.p, model.m, model.t, rule=MSBnew_rule)
John
--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
pyomo-forum...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyomo-forum/e3e48249-6194-45a9-b589-80c545992ad9n%40googlegroups.com.