Interface SolverJob<Solution_,ProblemId_>
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotationProblemId_- the ID type of a submitted problem, such asLongorUUID.
- All Known Implementing Classes:
DefaultSolverJob
public interface SolverJob<Solution_,ProblemId_>
Represents a
problem that has been submitted to solve on the SolverManager.-
Method Summary
Modifier and TypeMethodDescriptiondefault @NonNull CompletableFuture<Void>addProblemChange(@NonNull ProblemChange<Solution_> problemChange) As defined byaddProblemChanges(List), only for a single problem change.@NonNull CompletableFuture<Void>addProblemChanges(@NonNull List<ProblemChange<Solution_>> problemChangeList) Schedules a batch ofproblem changesto be processed by the underlyingSolverand returns immediately.@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.booleanvoidTerminates the solver or cancels the solver job if it hasn't (re)started yet.
-
Method Details
-
getProblemId
@NonNull ProblemId_ getProblemId()- Returns:
- a value given to
SolverManager.solve(Object, Object, Consumer)orSolverManager.solveAndListen(Object, Object, Consumer)
-
getSolverStatus
@NonNull SolverStatus getSolverStatus()Returns whether theSolveris scheduled to solve, actively solving or not.Returns
SolverStatus.NOT_SOLVINGif the solver already terminated. -
addProblemChange
default @NonNull CompletableFuture<Void> addProblemChange(@NonNull ProblemChange<Solution_> problemChange) As defined byaddProblemChanges(List), only for a single problem change. Prefer to submit multipleProblemChanges at once to reduce the considerable overhead of multiple calls. -
addProblemChanges
@NonNull CompletableFuture<Void> addProblemChanges(@NonNull List<ProblemChange<Solution_>> problemChangeList) Schedules a batch ofproblem changesto be processed by the underlyingSolverand returns immediately.- Parameters:
problemChangeList- at least one problem change to be processed- Returns:
- completes after the best solution containing this change has been consumed.
- Throws:
IllegalStateException- if the underlyingSolveris not in theSolverStatus.SOLVING_ACTIVEstate- See Also:
-
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
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. -
isTerminatedEarly
boolean isTerminatedEarly()- Returns:
- true if
terminateEarly()has been called since the underlyingSolverstarted solving.
-
getFinalBestSolution
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
@NonNull Duration getSolvingDuration()Returns 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.- Returns:
- the
Durationspent solving since the last (re)start, at least 0
-
getScoreCalculationCount
long getScoreCalculationCount()Return 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.- Returns:
- the number of score calculations that had occurred during solving since the last (re)start, at least 0
-
getMoveEvaluationCount
long getMoveEvaluationCount()Return 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.- Returns:
- the number of move evaluations that had occurred during solving since the last (re)start, at least 0
-
getProblemSizeStatistics
@NonNull ProblemSizeStatistics getProblemSizeStatistics() -
getScoreCalculationSpeed
long getScoreCalculationSpeed()Return 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.- Returns:
- the average number of score calculations per second that had occurred during solving since the last (re)start, at least 0
-
getMoveEvaluationSpeed
long getMoveEvaluationSpeed()Return 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.- Returns:
- the average number of move evaluations per second that had occurred during solving since the last (re)start, at least 0
-