Search code examples
pythonpyomo

How to model flow balance equation in Pyomo?


I need to specify the following equation in my Pyomo model:

w[t]=w[t-1]+y[t]+z[t]-v[t]

t is a time step, and w, y, z and v are variables that change over time steps. Should I model it as a constraint? I appreciate any example of how similar equations (maybe not exactly the same) are modeled.


Solution

  • Yes, you should model this as a constraint. Here is a small example to help you get started:

    m.t = Set(initialize=[1,2,3,4])
    m.w = Var(m.t)
    m.y = Var(m.t)
    
    def _flow_rule(m, t):
       if t == 1:
          return Constraint.Skip
       return m.w[t] == m.w[t-1] + m.y[t]
    m.flow = Constraint(m.t, rule=_flow_rule)