-
Notifications
You must be signed in to change notification settings - Fork 69
allow constant in objective cost function #539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
allow constant in objective cost function #539
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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. |
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.