Here is the offending code, abstracted from the source to protect your sanity . . .
def objective_rule(model):
return sum(model.ccv[c] * model.SELECT[c] for c in model.c)
nc=40
model.c = Set(initialize=[c for c in range(1, nc+1)], ordered=True)
model.SELECT=Var(model.c, initialize=0, domain=NonNegativeReals)
model.ccv= Param(model.c, initialize=ccd, domain=NonNegativeReals)
ccd is a dictionary with the same integer keys as as model.c.
Here are the error allegations made by pyomo.
ERROR: Initializer for Set objective_index returned non-iterable object of
type SumExpression.
ERROR: Constructing component 'objective_index' from data=None failed:
TypeError: 'SumExpression' object is not iterable
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In [44], line 1
----> 1 model.objective = Objective(objective_rule, sense = minimize)
3 print("Done setting up the problem.")
...
TypeError: 'SumExpression' object is not iterable
You'll notice that I don't use SumExpression in my code, so an error message that SumExpression is not iterable is not actionable.
The objection function follows the form of many, many other pyomo objective functions that do work fine.
The problem I'm working on is easy to solve in cvxpy, but I'm tasked with getting pyomo to be useful. So far, not so good.
Is there a (nonobvious) error here? Do the error messages contain actionable information? Do I have a broken pyomo installation?