Pyomo Creating A Variable Time Index
I'm trying to bring this constraint in my pyomo model [1 I define a set for indexing over time and I want to optimize the corresponding energy variable below model.grid_time = Set(
Solution 1:
Would something like this work?
defSum_rule(model, v, t):
returnsum(model.Ech[t2] for t2 in model.grid_time if t2 <= t) <= model.Edem[v,t]
model.Sum_constraint = Constraint(model.grid_time, model.V, rule=Sum_rule)
Essentially, what happens is that the t
in the Sum_rule(model, v, t)
makes sure that the constraint is called for each t
in model.grid_times
. The t2
in the sum is also part of model.grid_times
, but it will only take values that are smaller than the t
at which the constraint is called.
I am not sure if my constraint matches exactly your notation, as you have not provided all the information required (e.g. regarding the subscript v
of the E^dem
variable, but it will basically do what you want with the sum.
Post a Comment for "Pyomo Creating A Variable Time Index"