Class DefaultSolverManager<Solution_,ProblemId_>
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotationProblemId_- the ID type of submitted problem, such asLongorUUID.
- All Implemented Interfaces:
SolverManager<Solution_,,ProblemId_> AutoCloseable
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultSolverManager(SolverFactory<Solution_> solverFactory, SolverManagerConfig solverManagerConfig) -
Method Summary
Modifier and TypeMethodDescriptionaddProblemChange(ProblemId_ problemId, ProblemChange<Solution_> problemChange) Schedules aProblemChangeto be processed by the underlyingSolverand returns immediately.voidclose()Terminates all solvers, cancels all solver jobs that haven't (re)started yet and discards all queuedProblemChanges.getSolverStatus(ProblemId_ problemId) Returns if theSolveris scheduled to solve, actively solving or not.protected SolverJob<Solution_,ProblemId_> solve(ProblemId_ problemId, Function<? super ProblemId_, ? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer, Consumer<? super Solution_> finalBestSolutionConsumer, Consumer<? super Solution_> initializedSolutionConsumer, Consumer<? super Solution_> solverJobStartedConsumer, BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler, SolverConfigOverride<Solution_> configOverride) protected SolverJob<Solution_,ProblemId_> solveAndListen(ProblemId_ problemId, Function<? super ProblemId_, ? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer, Consumer<? super Solution_> finalBestSolutionConsumer, Consumer<? super Solution_> initializedSolutionConsumer, Consumer<? super Solution_> solverJobStartedConsumer, BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler, SolverConfigOverride<Solution_> solverConfigOverride) Creates a Builder that allows to customize and submit a planning problem to solve.voidterminateEarly(ProblemId_ problemId) Terminates the solver or cancels the solver job if it hasn't (re)started yet.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ai.timefold.solver.core.api.solver.SolverManager
solve, solve, solve, solve, solve, solveAndListen, solveAndListen, solveAndListen, solveAndListen
-
Constructor Details
-
DefaultSolverManager
public DefaultSolverManager(SolverFactory<Solution_> solverFactory, SolverManagerConfig solverManagerConfig)
-
-
Method Details
-
getSolverFactory
-
solveBuilder
Description copied from interface:SolverManagerCreates a Builder that allows to customize and submit a planning problem to solve.- Specified by:
solveBuilderin interfaceSolverManager<Solution_,ProblemId_> - Returns:
- never null
-
solveAndListen
protected SolverJob<Solution_,ProblemId_> solveAndListen(ProblemId_ problemId, Function<? super ProblemId_, ? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer, Consumer<? super Solution_> finalBestSolutionConsumer, Consumer<? super Solution_> initializedSolutionConsumer, Consumer<? super Solution_> solverJobStartedConsumer, BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler, SolverConfigOverride<Solution_> solverConfigOverride) -
solve
protected SolverJob<Solution_,ProblemId_> solve(ProblemId_ problemId, Function<? super ProblemId_, ? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer, Consumer<? super Solution_> finalBestSolutionConsumer, Consumer<? super Solution_> initializedSolutionConsumer, Consumer<? super Solution_> solverJobStartedConsumer, BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler, SolverConfigOverride<Solution_> configOverride) -
getSolverStatus
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 interfaceSolverManager<Solution_,ProblemId_> - Parameters:
problemId- never null, a value given toSolverManager.solve(Object, Object, Consumer)orSolverManager.solveAndListen(Object, Object, Consumer)- Returns:
- never null
-
addProblemChange
public CompletableFuture<Void> addProblemChange(ProblemId_ problemId, ProblemChange<Solution_> problemChange) Description copied from interface:SolverManagerSchedules aProblemChangeto be processed by the underlyingSolverand returns immediately. If the solver already terminated or the problemId was never added, throws an exception. The same applies if the underlyingSolveris not in theSolverStatus.SOLVING_ACTIVEstate.- Specified by:
addProblemChangein interfaceSolverManager<Solution_,ProblemId_> - Parameters:
problemId- never null, a value given toSolverManager.solve(Object, Object, Consumer)orSolverManager.solveAndListen(Object, Object, Consumer)problemChange- never null- Returns:
- completes after the best solution containing this change has been consumed.
-
terminateEarly
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. When the solver terminates, thefinalBestSolutionConsumeris executed with the latest best solution. These consumers run on a consumer thread independently of the termination and may still run even after this method returns.- Specified by:
terminateEarlyin interfaceSolverManager<Solution_,ProblemId_> - Parameters:
problemId- never null, a value given toSolverManager.solve(Object, Object, Consumer)orSolverManager.solveAndListen(Object, Object, Consumer)
-
close
public void close()Description copied from interface:SolverManagerTerminates all solvers, cancels all solver jobs that haven't (re)started yet and discards all queuedProblemChanges. Releases all thread pool resources.No new planning problems can be submitted after calling this method.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSolverManager<Solution_,ProblemId_>
-