Add Solver.resolve() and Model.apply_result() for iterative re-solve workflows#622
Open
FabianHofmann wants to merge 3 commits intomasterfrom
Open
Add Solver.resolve() and Model.apply_result() for iterative re-solve workflows#622FabianHofmann wants to merge 3 commits intomasterfrom
FabianHofmann wants to merge 3 commits intomasterfrom
Conversation
Collaborator
|
Cool addition. Also nice internal refactor. |
Collaborator
Author
|
not urgent at all, it is also not a big change and only slight refactor, so should not take long to review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #198
Changes proposed in this Pull Request
This PR adds support for iterative re-solve workflows where users solve a model once, modify the native solver object directly (e.g. change objective coefficients or bounds), and re-solve without rebuilding the linopy model.
New APIs:
Solver.resolve(solver_model, sense)— re-solves an existing native solver model and returns aResult. Implemented for HiGHS, Gurobi, and Mosek; raisesNotImplementedErrorfor other solvers.Model.apply_result(result, solver_name)— resets the current solution and maps a solverResultback onto the model's variables (primal) and constraints (dual).Refactoring:
Model.solve()has been extracted intoapply_result(), whichsolve()now calls internally. No behavioral change for existing users.Documentation:
examples/iterative-resolving.ipynbdemonstrating the full workflow: initial solve, native model modification, re-solve loop, parameter sweep, and infeasible result handling.Tests:
test/test_resolve.pycoveringapply_result(optimal, infeasible,Nonesolution),Highs.resolve()end-to-end, andNotImplementedErrorfor unsupported solvers.Checklist
doc.doc/release_notes.rstof the upcoming release is included.