polish CpSolver java

This commit is contained in:
Laurent Perron
2021-03-12 18:12:23 +01:00
parent 07cf6e38f3
commit 856ee71dc3

View File

@@ -40,7 +40,8 @@ public final class CpSolver {
/** Solves a problem and passes each solution found to the callback. */
public CpSolverStatus solveWithSolutionCallback(CpModel model, CpSolverSolutionCallback cb) {
createSolveWrapper();
// Setup search.
createSolveWrapper(); // Synchronized.
solveWrapper.setParameters(solveParameters.build());
if (cb != null) {
solveWrapper.addSolutionCallback(cb);
@@ -48,8 +49,15 @@ public final class CpSolver {
if (logCallback != null) {
solveWrapper.addLogCallback(logCallback);
}
solveResponse = solveWrapper.solve(model.model());
releaseSolveWrapper();
// Cleanup search.
if (cb != null) {
solveWrapper.clearSolutionCallback(cb);
}
releaseSolveWrapper(); // Synchronized.
return solveResponse.getStatus();
}