PyPSA / linopy

Linear optimization with N-D labeled arrays in Python
https://linopy.readthedocs.io
MIT License
155 stars 43 forks source link

Allow removing objective expression from the model #212

Closed Irieo closed 7 months ago

Irieo commented 7 months ago

Add functionality to remove a linear expression of the objective from the model. complements already existing functionality, such as remove_variables() and remove_constraints() Useful for tutorials, and more generally, for any type of programming exercises when one wants to keep variables and parameters from n.optimize.create_model() but use own objective.

example use:

n.optimize.create_model() n.model.objective

LinearExpression: +70 Generator-p[now, gas] Sense: min Value: None

n.model.remove_objective()

LinearExpression: +0 Sense: min Value: None

closes https://github.com/PyPSA/linopy/issues/209

codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (a97febe) 89.26% compared to head (ab97cca) 89.26%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #212 +/- ## ======================================= Coverage 89.26% 89.26% ======================================= Files 15 15 Lines 3352 3354 +2 Branches 771 771 ======================================= + Hits 2992 2994 +2 Misses 248 248 Partials 112 112 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

FabianHofmann commented 7 months ago

Awesome @Irieo, to increase the awesomeness, could you add a test for it, probably in test_model.py?

Irieo commented 7 months ago

Awesome @Irieo, to increase the awesomeness, could you add a test for it, probably in test_model.py?

indeed, let's keep the level of awesomeness pumped up. I added a test.