Package org.optaplanner.core.api.solver
Interface SolverJob<Solution_,ProblemId_>
-
- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotationProblemId_
- the ID type of a submitted problem, such asLong
orUUID
.
- All Known Implementing Classes:
DefaultSolverJob
public interface SolverJob<Solution_,ProblemId_>
Represents aproblem
that has been submitted to solve on theSolverManager
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Solution_
getFinalBestSolution()
Waits if necessary for the solver to complete and then returns the final bestPlanningSolution
.ProblemId_
getProblemId()
SolverStatus
getSolverStatus()
Returns whether theSolver
is scheduled to solve, actively solving or not.Duration
getSolvingDuration()
Returns theDuration
spent solving since the last start.void
terminateEarly()
Terminates the solver or cancels the solver job if it hasn't (re)started yet.
-
-
-
Method Detail
-
getProblemId
ProblemId_ getProblemId()
- Returns:
- never null, a value given to
SolverManager.solve(Object, Function, Consumer)
orSolverManager.solveAndListen(Object, Function, Consumer)
-
getSolverStatus
SolverStatus getSolverStatus()
Returns whether theSolver
is scheduled to solve, actively solving or not.Returns
SolverStatus.NOT_SOLVING
if the solver already terminated.- Returns:
- never null
-
terminateEarly
void terminateEarly()
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 (on a consumer thread), before this method returns.
-
getFinalBestSolution
Solution_ getFinalBestSolution() throws InterruptedException, ExecutionException
Waits if necessary for the solver to complete and then returns the final bestPlanningSolution
.- 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
Duration getSolvingDuration()
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.- Returns:
- the
Duration
spent solving since the last (re)start, at least 0
-
-