Skip to content
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 6 commits into from
Apr 16, 2024
Merged

Conversation

nhuet
Copy link
Contributor

@nhuet nhuet commented Apr 9, 2024

We use the instance.output_type as an entry point.
During the solve() call, we create dynamically a subclass of MinizincCPSolution which:

  • wraps 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 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:

  • when using latest version of minzinc, rcpsp_multiskill solver was raising an issue, we fixed the minizinc file defining the model
  • we upgrade the minizinc version used by github runners to test compatibility of our solvers with latest version of minizinc
  • we fix CP_MULTISCENARIO, which was not really filling the result storage with solutions but rather with tuple of solutions for different variations of the same model. Instead,we make it work on AggregRCPSPModel so that the fitness is computed correctly on the list of submodels.

@nhuet nhuet force-pushed the mzn-cb branch 4 times, most recently from 7edb880 to ac66bf6 Compare April 12, 2024 13:11
@nhuet nhuet marked this pull request as ready for review April 12, 2024 14:07
@nhuet nhuet force-pushed the mzn-cb branch 3 times, most recently from a641b1f to 22985c0 Compare April 16, 2024 12:52
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.
nhuet added 2 commits April 16, 2024 15:03
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.
nhuet and others added 3 commits April 16, 2024 16:31
It comes with ortools already configured which is used in one of the
tests.
- 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)
Copy link
Collaborator

@g-poveda g-poveda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@g-poveda g-poveda merged commit 3d1cde5 into airbus:master Apr 16, 2024
14 checks passed
@nhuet nhuet deleted the mzn-cb branch April 19, 2024 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants