-
Notifications
You must be signed in to change notification settings - Fork 11
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
Implement callbacks for minizinc-based solvers #187
Merged
Merged
Conversation
This file contains 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
nhuet
force-pushed
the
mzn-cb
branch
4 times, most recently
from
April 12, 2024 13:11
7edb880
to
ac66bf6
Compare
nhuet
force-pushed
the
mzn-cb
branch
3 times, most recently
from
April 16, 2024 12:52
a641b1f
to
22985c0
Compare
We use the instance.output_type as an entry point. During the solve() call, we create dynamically a subclass of MinizincCPSolution which - wrapps an actual d-o solution - has class attributes properly initialized for tracking - full ResultStorage - current number of step - solver instance - user-defined callbacks This class will be called each time a new solution is found by minizinc, and thus update the result storage and call upon user-defined callbacks. If a stopping criteria is reached in callbacks, we raise a SolveEarlyStop exception which will be caught in solve(). In addition to that a MinizincCPSolver must now implement `retrieve_solution()` which converts a solution from minzinc into a d-o one. It replaces retrieve_solutions() and means that solutions will be converted on the fly, and directly added to the current result_storage.
Fix also the way to lookup for underlying minzinc solver to use, by using find_right_minizinc_solver_name() each time.
- This avoids having to specify the internals of solving twice (like translating parameters_cp into acutla args for instance.solve()) - This allows to directly get the result storage (retrieve_solutions not existing anymore) - We added an argument instance for cp_solver.solve() to allow using the child instance instead the original cp_solver.instance During the process, we fix an error in logger.warning() raised when the cp_solver fails.
It comes with ortools already configured which is used in one of the tests.
… with minizinc 2.8.3
- Make it solve AggregRCPSPModel - Make retrieve_solution return a solution (and not a list) - Add minzinc objective to RCPSPSolution attributes in retrieve_solution (to make work robustness_experiments example) - Fix AggregRCPSPModel by calling RCPSPModel.__init__ to generate missing attributes - Previous evaluation computed in retrieve_solution corresponds to the fitness that will be computed by AggregRCPSPModel on a RCPSPSolution - Adapt example - Add a test for this solver (which will moreover test AggregRCPSPModel)
g-poveda
approved these changes
Apr 16, 2024
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.
👍
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.
We use the
instance.output_type
as an entry point.During the
solve()
call, we create dynamically a subclass ofMinizincCPSolution
which:ResultStorage
This class will be called each time a new solution is found by minizinc, and thus update the result storage and call upon user-defined callbacks.
If a stopping criteria is reached in callbacks, we raise a
SolveEarlyStop
exception which will be caught insolve()
.In addition to that a
MinizincCPSolver
must now implementretrieve_solution()
which converts a solution from minzinc into a d-o one.
It replaces former
retrieve_solutions()
and means that solutions will be now converted on the fly, and directly added to the current result_storage.We also fix other bugs in minizinc solvers on the way: