Construct Pyomo Objective

Viewed 24

Hi I am trying to solve the following objective in pyomo. Here is my code

C={'A':['B','C','D'], 'E':['F','G']}
year=[1,2,3,4]

for key,value in C.items():
  for y in year :
     sum([model.x[asset , y] for asset in value]) # maximise only this one

model.obj = pyo.Objective(
        expr=sum([model.x[asset , y] for asset in value ])for key,value in C.items() for y in year), sense=pyo.minimize)
 

I would only want to sum the value in the a certain loop not the total loop but not sure how to do that. So the solutions will be: year 1, year 2 , year 3 , year 4, year 5 B D C

D sometimes can go to year 2 due to some constrains but that is fine just not sure how to construct the objective.

0 Answers
Related