Adding a term to objective with linopy

40 views
Skip to first unread message

gktho...@gmail.com

unread,
Mar 3, 2023, 8:28:36 AM3/3/23
to pypsa
Hi everybody,

I am trying currently to add a new term to the objective function, using the linopy functionality. Somehow, it is not very successful, the result with and without the term is identical. Therefore I wanted to ask what I am doing wrong.
The code I am using, in short, is the following:

m = n.optimize.create_model()
gen_p = m["Generator-p"]
m.objective += gen_p.loc[:, n.generators.query("carrier == 'nuclear'").index].sum()*1e9
n.optimize(solver_name='highs')

Normally it should aim to minimize nuclear production, but I do not see a difference when I add the term to the objective.

Thanks a lot in advance!

Best,
Georg


gktho...@gmail.com

unread,
Mar 3, 2023, 9:27:11 AM3/3/23
to pypsa
Okay I actually already managed. One small part was missing, I will post the solution here, in case someone runs into the same issue :-)

m = n.optimize.create_model()
gen_p = m["Generator-p"]
obj = m.objective
obj += gen_p.loc[:, n.generators.query("carrier == 'nuclear'").index].sum()*1e20
m.add_objective(obj, overwrite=True)
n.optimize.solve_model(solver_name='highs')
Reply all
Reply to author
Forward
0 new messages