-
Notifications
You must be signed in to change notification settings - Fork 25
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
Allow finding intermediate solutions with Minizinc #251
Comments
For some additional context, I pass |
The easiest solution would be to simply have an argument change this behavior of |
For those looking for a workaround, I extended the class MinizincSolver(CPM_minizinc):
"""
Wrapper around CPM_minizinc that allows capturing all (intermediate) solutions,
because CPM_minizinc abandons all but the last solution
"""
objective_values: List[int]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.objective_values = []
def _post_solve(self, mzn_result):
solutions = mzn_result.solution if is_any_list(mzn_result.solution) else [mzn_result.solution]
for sol in solutions:
self.objective_values.append(sol.objective)
return super()._post_solve(mzn_result) I then call |
Hi Tim, I think that is a very elegant solution. To have something to main CPMpy would indeed be best with a callback, but if the above solution suits you well then I think we can leave it at that? |
Yes, this works for me. We can leave it at that, but it may be nice for future users. However, I am not sure how common this requirement is |
I am trying to find all intermediate solutions for an optimization problem.
CPM_minizinc
does not allow this, assolve()
will only return the last solution, andsolveAll()
does not work for optimization problems. I did not encounter this problem for theCPM_ortools
model, where I can provide a callback tosolve()
to store all intermediate solutions myselfThe text was updated successfully, but these errors were encountered: