The Pyomo book proposes this structure of blocks for a time-dependent problem.
There is a Pyomo Block 'Electrical Grid Model' which is repeated for every time step, means indexed by the time series.
model.T = range(120)
def electrical_grid_block(grid, t):
<containing: bus, transmission line, generator>
model.Grid = Block(model.T,rule=electrical_grid_block)
Makes totally sense to me until I want to model blocks which have to refer to a past time step. For example a storage needs the value of its storage level from last time step. The only solution I thought of: skipping the idea of indexed blocks and passing the time series into the storage block like this:
def storage(s):
s.storage_level = Var(model.T, bounds=(0,300))
s.power = Var(model.T, bounds=(-2,2))
# Constraints
def constr_rule_speicher(s,t):
if t >= 2:
return s.storage_level[t] == - s.power[t] * dt + s.storage_level[t-1]
elif t == 1:
return s.storage_level[t] == 150.0
s.storage_constraints = Constraint(model.T, rule=constr_rule_speicher)
model.storage = Block(rule=storage)
I don't like this solution very much because I believe the object oriented manner of problem modeling gets lost.
Any different ideas to mine?
Unfortunately the documentation around Pyomo doesn't give any example for this kind of case.