Class DefaultSolverJob<Solution_,ProblemId_>
java.lang.Object
ai.timefold.solver.core.impl.solver.DefaultSolverJob<Solution_,ProblemId_>
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotationProblemId_- the ID type of submitted problem, such asLongorUUID.
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultSolverJob(DefaultSolverManager<Solution_, ProblemId_> solverManager, Solver<Solution_> solver, ProblemId_ problemId, Function<? super ProblemId_, ? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer, Consumer<? super Solution_> finalBestSolutionConsumer, SolverJobBuilder.FirstInitializedSolutionConsumer<? super Solution_> firstInitializedSolutionConsumer, Consumer<? super Solution_> solverJobStartedConsumer, BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler) -
Method Summary
Modifier and TypeMethodDescription@NonNull CompletableFuture<Void>addProblemChanges(@NonNull List<ProblemChange<Solution_>> problemChangeList) Schedules a batch ofproblem changesto be processed by the underlyingSolverand returns immediately.call()@NonNull Solution_Waits if necessary for the solver to complete and then returns the final bestPlanningSolution.longReturn the number of move evaluations since the last start.longReturn the average number of move evaluations per second since the last start.@NonNull ProblemId_@NonNull ProblemSizeStatisticslongReturn the number of score calculations since the last start.longReturn the average number of score calculations per second since the last start.@NonNull SolverStatusReturns whether theSolveris scheduled to solve, actively solving or not.@NonNull DurationReturns theDurationspent solving since the last start.booleanvoidsetFinalBestSolutionFuture(Future<Solution_> finalBestSolutionFuture) voidTerminates 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.SolverJob
addProblemChange
-
Constructor Details
-
DefaultSolverJob
public DefaultSolverJob(DefaultSolverManager<Solution_, ProblemId_> solverManager, Solver<Solution_> solver, ProblemId_ problemId, Function<? super ProblemId_, ? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer, Consumer<? super Solution_> finalBestSolutionConsumer, SolverJobBuilder.FirstInitializedSolutionConsumer<? super Solution_> firstInitializedSolutionConsumer, Consumer<? super Solution_> solverJobStartedConsumer, BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler)
-
-
Method Details
-
setFinalBestSolutionFuture
-
getProblemId
- Specified by:
getProblemIdin interfaceSolverJob<Solution_,ProblemId_> - Returns:
- a value given to
SolverManager.solve(Object, Object, Consumer)orSolverManager.solveAndListen(Object, Object, Consumer)
-
getSolverStatus
Description copied from interface:SolverJobReturns whether theSolveris scheduled to solve, actively solving or not.Returns
SolverStatus.NOT_SOLVINGif the solver already terminated.- Specified by:
getSolverStatusin interfaceSolverJob<Solution_,ProblemId_>
-
call
-
addProblemChanges
public @NonNull CompletableFuture<Void> addProblemChanges(@NonNull List<ProblemChange<Solution_>> problemChangeList) Description copied from interface:SolverJobSchedules a batch ofproblem changesto be processed by the underlyingSolverand returns immediately.- Specified by:
addProblemChangesin interfaceSolverJob<Solution_,ProblemId_> - Parameters:
problemChangeList- at least one problem change to be processed- Returns:
- completes after the best solution containing this change has been consumed.
- See Also:
-
terminateEarly
public void terminateEarly()Description copied from interface:SolverJobTerminates the solver or cancels the solver job if it hasn't (re)started yet.Does nothing if the solver already terminated.
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 interfaceSolverJob<Solution_,ProblemId_>
-
isTerminatedEarly
public boolean isTerminatedEarly()- Specified by:
isTerminatedEarlyin interfaceSolverJob<Solution_,ProblemId_> - Returns:
- true if
SolverJob.terminateEarly()has been called since the underlyingSolverstarted solving.
-
getFinalBestSolution
Description copied from interface:SolverJobWaits if necessary for the solver to complete and then returns the final bestPlanningSolution.- Specified by:
getFinalBestSolutionin interfaceSolverJob<Solution_,ProblemId_> - Returns:
- never null, but it could be the original uninitialized problem
- Throws:
InterruptedException- if the current thread was interrupted while waitingExecutionException- if the computation threw an exception
-
getSolvingDuration
Description copied from interface:SolverJobReturns theDurationspent solving since the last start. If it hasn't started it yet, it returnsDuration.ZERO. If it hasn't ended yet, it returns the time between the last start and now. If it has ended already, it returns the time between the last start and the ending.- Specified by:
getSolvingDurationin interfaceSolverJob<Solution_,ProblemId_> - Returns:
- the
Durationspent solving since the last (re)start, at least 0
-
getScoreCalculationCount
public long getScoreCalculationCount()Description copied from interface:SolverJobReturn the number of score calculations since the last start. If it hasn't started yet, it returns 0. If it hasn't ended yet, it returns the number of score calculations so far. If it has ended already, it returns the total number of score calculations that occurred during solving.- Specified by:
getScoreCalculationCountin interfaceSolverJob<Solution_,ProblemId_> - Returns:
- the number of score calculations that had occurred during solving since the last (re)start, at least 0
-
getMoveEvaluationCount
public long getMoveEvaluationCount()Description copied from interface:SolverJobReturn the number of move evaluations since the last start. If it hasn't started yet, it returns 0. If it hasn't ended yet, it returns the number of moves evaluations so far. If it has ended already, it returns the total number of move evaluations that occurred during solving.- Specified by:
getMoveEvaluationCountin interfaceSolverJob<Solution_,ProblemId_> - Returns:
- the number of move evaluations that had occurred during solving since the last (re)start, at least 0
-
getScoreCalculationSpeed
public long getScoreCalculationSpeed()Description copied from interface:SolverJobReturn the average number of score calculations per second since the last start. If it hasn't started yet, it returns 0. If it hasn't ended yet, it returns the average number of score calculations per second so far. If it has ended already, it returns the average number of score calculations per second during solving.- Specified by:
getScoreCalculationSpeedin interfaceSolverJob<Solution_,ProblemId_> - Returns:
- the average number of score calculations per second that had occurred during solving since the last (re)start, at least 0
-
getMoveEvaluationSpeed
public long getMoveEvaluationSpeed()Description copied from interface:SolverJobReturn the average number of move evaluations per second since the last start. If it hasn't started yet, it returns 0. If it hasn't ended yet, it returns the average number of move evaluations per second so far. If it has ended already, it returns the average number of move evaluations per second during solving.- Specified by:
getMoveEvaluationSpeedin interfaceSolverJob<Solution_,ProblemId_> - Returns:
- the average number of move evaluations per second that had occurred during solving since the last (re)start, at least 0
-
getProblemSizeStatistics
Description copied from interface:SolverJob- Specified by:
getProblemSizeStatisticsin interfaceSolverJob<Solution_,ProblemId_>
-
getSolverTermination
-