Class DefaultSolverManager<Solution_,ProblemId_>
- java.lang.Object
- 
- org.optaplanner.core.impl.solver.DefaultSolverManager<Solution_,ProblemId_>
 
- 
- Type Parameters:
- Solution_- the solution type, the class with the- PlanningSolutionannotation
- ProblemId_- the ID type of a submitted problem, such as- Longor- UUID.
 - All Implemented Interfaces:
- AutoCloseable,- SolverManager<Solution_,ProblemId_>
 
 public final class DefaultSolverManager<Solution_,ProblemId_> extends Object implements SolverManager<Solution_,ProblemId_> 
- 
- 
Constructor SummaryConstructors Constructor Description DefaultSolverManager(SolverFactory<Solution_> solverFactory, SolverManagerConfig solverManagerConfig)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Terminates all solvers, cancels all solver jobs that haven't (re)started yet and discards all queuedProblemFactChanges.SolverFactory<Solution_>getSolverFactory()SolverStatusgetSolverStatus(ProblemId_ problemId)Returns if theSolveris scheduled to solve, actively solving or not.SolverJob<Solution_,ProblemId_>solve(ProblemId_ problemId, Function<? super ProblemId_,? extends Solution_> problemFinder, Consumer<? super Solution_> finalBestSolutionConsumer, BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler)As defined bySolverManager.solve(Object, Function, Consumer).protected SolverJob<Solution_,ProblemId_>solve(ProblemId_ problemId, Function<? super ProblemId_,? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer, Consumer<? super Solution_> finalBestSolutionConsumer, BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler)SolverJob<Solution_,ProblemId_>solveAndListen(ProblemId_ problemId, Function<? super ProblemId_,? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer, Consumer<? super Solution_> finalBestSolutionConsumer, BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler)As defined bySolverManager.solveAndListen(Object, Function, Consumer).voidterminateEarly(ProblemId_ problemId)Terminates the solver or cancels the solver job if it hasn't (re)started yet.protected voidunregisterSolverJob(ProblemId_ problemId)- 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.optaplanner.core.api.solver.SolverManagersolve, solve, solve, solve, solveAndListen, solveAndListen
 
- 
 
- 
- 
- 
Constructor Detail- 
DefaultSolverManagerpublic DefaultSolverManager(SolverFactory<Solution_> solverFactory, SolverManagerConfig solverManagerConfig) 
 
- 
 - 
Method Detail- 
getSolverFactorypublic SolverFactory<Solution_> getSolverFactory() 
 - 
solvepublic SolverJob<Solution_,ProblemId_> solve(ProblemId_ problemId, Function<? super ProblemId_,? extends Solution_> problemFinder, Consumer<? super Solution_> finalBestSolutionConsumer, BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler) Description copied from interface:SolverManagerAs defined bySolverManager.solve(Object, Function, Consumer).- Specified by:
- solvein interface- SolverManager<Solution_,ProblemId_>
- Parameters:
- problemId- never null, a ID for each planning problem. This must be unique. Use this problemId to- terminatethe solver early,- to get the statusor if the problem changes while solving.
- problemFinder- never null, function that returns a- PlanningSolution, usually with uninitialized planning variables
- finalBestSolutionConsumer- sometimes null, called only once, at the end, on a consumer thread
- exceptionHandler- sometimes null, called if an exception or error occurs. If null it defaults to logging the exception as an error.
- Returns:
- never null
 
 - 
solveAndListenpublic SolverJob<Solution_,ProblemId_> solveAndListen(ProblemId_ problemId, Function<? super ProblemId_,? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer, Consumer<? super Solution_> finalBestSolutionConsumer, BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler) Description copied from interface:SolverManagerAs defined bySolverManager.solveAndListen(Object, Function, Consumer).The final best solution is delivered twice: first to the bestSolutionConsumerwhen it is found and then again to thefinalBestSolutionConsumerwhen the solver terminates. Do not store the solution twice. This allows for use cases that only process theScorefirst (during best solution changed events) and then store the solution upon termination.- Specified by:
- solveAndListenin interface- SolverManager<Solution_,ProblemId_>
- Parameters:
- problemId- never null, an ID for each planning problem. This must be unique. Use this problemId to- terminatethe solver early,- to get the statusor if the problem changes while solving.
- problemFinder- never null, function that returns a- PlanningSolution, usually with uninitialized planning variables
- bestSolutionConsumer- never null, called multiple times, on a consumer thread
- finalBestSolutionConsumer- sometimes null, called only once, at the end, on a consumer thread. That final best solution is already consumed by the bestSolutionConsumer earlier.
- exceptionHandler- sometimes null, called if an exception or error occurs. If null it defaults to logging the exception as an error.
- Returns:
- never null
 
 - 
solveprotected SolverJob<Solution_,ProblemId_> solve(ProblemId_ problemId, Function<? super ProblemId_,? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer, Consumer<? super Solution_> finalBestSolutionConsumer, BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler) 
 - 
getSolverStatuspublic SolverStatus getSolverStatus(ProblemId_ problemId) Description copied from interface:SolverManagerReturns if theSolveris scheduled to solve, actively solving or not.Returns SolverStatus.NOT_SOLVINGif the solver already terminated or if the problemId was never added. To distinguish between both cases, useSolverJob.getSolverStatus()instead. Here, that distinction is not supported because it would cause a memory leak.- Specified by:
- getSolverStatusin interface- SolverManager<Solution_,ProblemId_>
- Parameters:
- problemId- never null, a value given to- SolverManager.solve(Object, Function, Consumer)or- SolverManager.solveAndListen(Object, Function, Consumer)
- Returns:
- never null
 
 - 
terminateEarlypublic void terminateEarly(ProblemId_ problemId) Description copied from interface:SolverManagerTerminates the solver or cancels the solver job if it hasn't (re)started yet.Does nothing if the solver already terminated or the problemId was never added. To distinguish between both cases, use SolverJob.terminateEarly()instead. Here, that distinction is not supported because it would cause a memory leak.Waits for the termination or cancellation to complete before returning. During termination, a bestSolutionConsumercould still be called (on a consumer thread), before this method returns.- Specified by:
- terminateEarlyin interface- SolverManager<Solution_,ProblemId_>
- Parameters:
- problemId- never null, a value given to- SolverManager.solve(Object, Function, Consumer)or- SolverManager.solveAndListen(Object, Function, Consumer)
 
 - 
closepublic void close() Description copied from interface:SolverManagerTerminates all solvers, cancels all solver jobs that haven't (re)started yet and discards all queuedProblemFactChanges. Releases all thread pool resources.No new planning problems can be submitted after calling this method. - Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- SolverManager<Solution_,ProblemId_>
 
 - 
unregisterSolverJobprotected void unregisterSolverJob(ProblemId_ problemId) 
 
- 
 
-