allow constant in objective cost function#539
allow constant in objective cost function#539RobbieKiwi wants to merge 16 commits intoPyPSA:masterfrom
Conversation
for more information, see https://pre-commit.ci
…/linopy into feature/constant-in-objective
FabianHofmann
left a comment
There was a problem hiding this comment.
@RobbieKiwi thank you for the pr! I need a bit more time to think about the approach you've taken. I would rather like to have the constant integrated in the full pipeline, such that it appears at the solver side as well (and skip those which are not supporting it). because now you would always see a discrepancy between the linopy objective and the solver objective which on the one hand is confusing, on the other make debugging other things harder.
|
@FabianHofmann what if we added a dummy variable and constrained it to be a certain value and included it in the objective cost function seen by the solver? |
|
Hey @RobbieKiwi this does unfortunately lead to a wide range in the objective function as soon as the constant is larger then the variables which can easily happen. So that would be also suboptimal. |
|
@FabianHofmann |
Closes #236
Changes proposed in this Pull Request
Allow the objective cost function to contain a constant. While the constant is not needed for optimization, it can make life easier in some cases (see linked issue for discussion).
It was previously forbidden to have a constant in the objective cost function, I assume this is because most solvers expect the ocf to only contain variables.
Now the objective can contain a constant if it is explicitly allowed with
Otherwise adding an objective with a constant will result in an error.
A bit of refactoring was required. To avoid having to repeat the same logic on multiple code paths and touch too much of the core solve logic, I made a decorator which strips the constant term before calling the
Model.solvemethod and then adds it back again after.Checklist
doc.doc/release_notes.rstof the upcoming release is included.