# Pyomo: Is this triple summation objective function formatted correctly?

I am writing a Pyomo model and trying to code the following mathematical constraint:

$$\sum_{i=1}^I\sum_{j=1}^J\sum_{t=1}^T 5I_{ijt} + 10L_{ijt}I_{ijt}$$ where $$L_{ijt}$$ is binary.

However, I am hoping that I could get someone to clarify if what I have written in my model makes sense:

def objective_rule(model):
return sum (sum (sum (model.obj[i,j,t] for i in model.Iset ) for j in model.Jset ) for t in model.Tset )
model.damages = Objective(rule=objective_rule, sense=minimize)

def obj_rule(model, i,j,t):
return model.obj[i,j,t] == 5*model.inf_b4treat[i,j,t] + 10 *model.level1[i,j,t]*model.inf_b4treat[i,j,t]
model.object = Constraint(model.Iset, model.Jset, model.Tset, rule=obj_rule)


I am getting a couple of strange results and having debugged my model I am thinking that it might be due to my objective function not being formatted properly. To clarify, the reason that I chose to create an additional object called model.obj[i,j,t] is so that I could access the objective function values after I solve the model.

I would appreciate any corrections.

• It might be easier for people to help you if you can provide a minimum working example, which demonstrates your "strange results". – Kevin Dalmeijer Sep 19 '19 at 2:27
• I think you probably can change it to sum(model.obj[i,j,t] for i in model.Iset for j in model.Jset for t in model.Tset) but it should be the same. Can you provide additional information on the other variables? What type are they and what bounds do they have? – JakobS Sep 19 '19 at 11:07
• To @KevinDalmeijer's comment, here's OR.SE's version of the minimum working example page. – LarrySnyder610 Sep 20 '19 at 2:53
• Cool, good to know we have our own! – Kevin Dalmeijer Sep 20 '19 at 3:01
• The expression given in your example seems like it is not a constraint but the way you coded it in your Pyomo code, it is the right-hand side of a constraint for which the left-hand side expression is missing in your example. Is that correct? What would be the complete constraint rule? – V. Brunelle Sep 26 '19 at 16:33

def objective_rule(model):

model.objective_rule.pprint()