Package org.optaplanner.core.impl.solver
Class DefaultSolverJob<Solution_,ProblemId_>
java.lang.Object
org.optaplanner.core.impl.solver.DefaultSolverJob<Solution_,ProblemId_>
- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotationProblemId_
- the ID type of submitted problem, such asLong
orUUID
.
-
Constructor Summary
ConstructorDescriptionDefaultSolverJob
(DefaultSolverManager<Solution_, ProblemId_> solverManager, Solver<Solution_> solver, ProblemId_ problemId, Function<? super ProblemId_, ? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer, Consumer<? super Solution_> finalBestSolutionConsumer, BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler) -
Method Summary
Modifier and TypeMethodDescriptionaddProblemChange
(ProblemChange<Solution_> problemChange) Schedules aProblemChange
to be processed by the underlyingSolver
and returns immediately.call()
Waits if necessary for the solver to complete and then returns the final bestPlanningSolution
.Returns whether theSolver
is scheduled to solve, actively solving or not.Returns theDuration
spent solving since the last start.boolean
void
setFinalBestSolutionFuture
(Future<Solution_> finalBestSolutionFuture) void
Terminates the solver or cancels the solver job if it hasn't (re)started yet.
-
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, BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler)
-
-
Method Details
-
setFinalBestSolutionFuture
-
getProblemId
- Specified by:
getProblemId
in interfaceSolverJob<Solution_,
ProblemId_> - Returns:
- never null, a value given to
SolverManager.solve(Object, Function, Consumer)
orSolverManager.solveAndListen(Object, Function, Consumer)
-
getSolverStatus
Description copied from interface:SolverJob
Returns whether theSolver
is scheduled to solve, actively solving or not.Returns
SolverStatus.NOT_SOLVING
if the solver already terminated.- Specified by:
getSolverStatus
in interfaceSolverJob<Solution_,
ProblemId_> - Returns:
- never null
-
call
-
addProblemChange
Description copied from interface:SolverJob
Schedules aProblemChange
to be processed by the underlyingSolver
and returns immediately.To learn more about problem change semantics, please refer to the
ProblemChange
Javadoc.- Specified by:
addProblemChange
in interfaceSolverJob<Solution_,
ProblemId_> - Parameters:
problemChange
- never null- Returns:
- completes after the best solution containing this change has been consumed.
-
terminateEarly
public void terminateEarly()Description copied from interface:SolverJob
Terminates 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
bestSolutionConsumer
could still be called. When the solver terminates, thefinalBestSolutionConsumer
is 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:
terminateEarly
in interfaceSolverJob<Solution_,
ProblemId_>
-
isTerminatedEarly
public boolean isTerminatedEarly()- Specified by:
isTerminatedEarly
in interfaceSolverJob<Solution_,
ProblemId_> - Returns:
- true if
SolverJob.terminateEarly()
has been called since the underlyingSolver
started solving.
-
getFinalBestSolution
Description copied from interface:SolverJob
Waits if necessary for the solver to complete and then returns the final bestPlanningSolution
.- Specified by:
getFinalBestSolution
in 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:SolverJob
Returns theDuration
spent 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:
getSolvingDuration
in interfaceSolverJob<Solution_,
ProblemId_> - Returns:
- the
Duration
spent solving since the last (re)start, at least 0
-