2
$\begingroup$

I would like to define a difference equation in pyomo for a temperature variable. The equation (simplified) looks like: $Temperature(t) = Temperature (t-1) + x(t)$ , for t>0

$Temperature (0) = 20 $

So this is what I tried in Pyomo

model.set_timeslots = pyo.RangeSet(0,95)  

model.variable_x = pyo.Var(model.set_timeslots, within=pyo.Binary)  
model.variable_temperature[0].fix(20)

def temperatureConstraintRule(model):
    model.variable_temperature(t) = model.variable_temperature(t-1) + model.variable_x(t) 
model.constraint_temperature = pyo.Constraint (model.set_timeslots, rule=temperatureConstraintRule)

However, I get the error message "SyntaxError: can't assign to function call"

Can anybody tell me how I can implement this difference equation in Pyomo?

$\endgroup$
3
$\begingroup$

try:

model.set_timeslots = pyo.RangeSet(0,95)  

model.variable_x = pyo.Var(model.set_timeslots, within=pyo.Binary)  
i0 = 20

def temperatureConstraintRule(model, t):
    if t == model.set_timeslots.first():
         return model.variable_x[t] == i0 + model.variable_x[t]
    return model.variable_x[t] == model.variable_x[t-1] + model.variable_x[t]
model.constraint_temperature = Constraint(model.set_timeslots, rule=temperatureConstraintRule)
$\endgroup$
2
  • 1
    $\begingroup$ Cool. Thank you Steven. Your suggested code seems to work. I upvoted and accepted your answer. $\endgroup$ – PeterBe Feb 22 at 17:37
  • $\begingroup$ Glad it helped @PeterBe $\endgroup$ – Steven01123581321 Feb 22 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.