Interface SolverJob<Solution_,ProblemId_>

Type Parameters:
Solution_ - the solution type, the class with the PlanningSolution annotation
ProblemId_ - the ID type of a submitted problem, such as Long or UUID.
All Known Implementing Classes:
DefaultSolverJob

public interface SolverJob<Solution_,ProblemId_>
Represents a problem that has been submitted to solve on the SolverManager.
  • Method Details

    • getProblemId

      ProblemId_ getProblemId()
      Returns:
      never null, a value given to SolverManager.solve(Object, Function, Consumer) or SolverManager.solveAndListen(Object, Function, Consumer)
    • getSolverStatus

      SolverStatus getSolverStatus()
      Returns whether the Solver is scheduled to solve, actively solving or not.

      Returns SolverStatus.NOT_SOLVING if the solver already terminated.

      Returns:
      never null
    • addProblemChange

      CompletableFuture<Void> addProblemChange(ProblemChange<Solution_> problemChange)
      Schedules a ProblemChange to be processed by the underlying Solver and returns immediately.

      To learn more about problem change semantics, please refer to the ProblemChange Javadoc.

      Parameters:
      problemChange - never null
      Returns:
      completes after the best solution containing this change has been consumed.
      Throws:
      IllegalStateException - if the underlying Solver is not in the SolverStatus.SOLVING_ACTIVE state
    • 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. When the solver terminates, the finalBestSolutionConsumer 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.

    • isTerminatedEarly

      boolean isTerminatedEarly()
      Returns:
      true if terminateEarly() has been called since the underlying Solver started solving.
    • getFinalBestSolution

      Solution_ getFinalBestSolution() throws InterruptedException, ExecutionException
      Waits if necessary for the solver to complete and then returns the final best PlanningSolution.
      Returns:
      never null, but it could be the original uninitialized problem
      Throws:
      InterruptedException - if the current thread was interrupted while waiting
      ExecutionException - if the computation threw an exception
    • getSolvingDuration

      Duration getSolvingDuration()
      Returns the Duration spent solving since the last start. If it hasn't started it yet, it returns Duration.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