I have a question about referecing set in Pyomo objectives. Basically I have 2 options and I do not understand why one of it works whereas the other yields an error. Here you see them:
model.set_timeslots = pyo.RangeSet(0,95)
#Option1
def ObjectiveRule (model):
return sum(model.variable_heatGeneration[t] for t in model.set_timeslots)
model.objective_costs = pyo.Objective( rule=ObjectiveRule, sense =pyo.minimize)
#Option 2
def ObjectiveRule_2 (model, t):
return sum(model.variable_heatGeneration[t])
model.objective_costs = pyo.Objective(model.set_timeslots, rule=ObjectiveRule_2, sense =pyo.minimize)
The second options leads to the error
TypeError: '_GeneralVarData' object is not iterable
Can you tell me what the difference is and why the second option does not work?
Reminder: Can nobody tell me what the difference is?