Interface SolverJobBuilder<Solution_,ProblemId_>

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

public interface SolverJobBuilder<Solution_,ProblemId_>
Provides a fluent contract that allows customization and submission of planning problems to solve.

A SolverManager can solve multiple planning problems and can be used across different threads.

Hence, it is possible to have multiple distinct build configurations that are scheduled to run by the SolverManager instance.

To solve a planning problem, set the problem configuration: withProblemId(Object), withProblemFinder(Function) and withProblem(Object).

Then solve it by calling run().

  • Method Details

    • withProblemId

      SolverJobBuilder<Solution_,ProblemId_> withProblemId(ProblemId_ problemId)
      Sets the problem id.
      Parameters:
      problemId - never null, a ID for each planning problem. This must be unique.
      Returns:
      this, never null
    • withProblem

      default SolverJobBuilder<Solution_,ProblemId_> withProblem(Solution_ problem)
      Sets the problem definition.
      Parameters:
      problem - never null, a PlanningSolution usually with uninitialized planning variables
      Returns:
      this, never null
    • withProblemFinder

      SolverJobBuilder<Solution_,ProblemId_> withProblemFinder(Function<? super ProblemId_,? extends Solution_> problemFinder)
      Sets the mapping function to the problem definition.
      Parameters:
      problemFinder - never null, a function that returns a PlanningSolution, usually with uninitialized planning variables
      Returns:
      this, never null
    • withBestSolutionConsumer

      SolverJobBuilder<Solution_,ProblemId_> withBestSolutionConsumer(Consumer<? super Solution_> bestSolutionConsumer)
      Sets the best solution consumer, which may be called multiple times during the solving process.
      Parameters:
      bestSolutionConsumer - never null, called multiple times for each new best solution on a consumer thread
      Returns:
      this, never null
    • withFinalBestSolutionConsumer

      SolverJobBuilder<Solution_,ProblemId_> withFinalBestSolutionConsumer(Consumer<? super Solution_> finalBestSolutionConsumer)
      Sets the final best solution consumer, which is called at the end of the solving process and returns the final best solution.
      Parameters:
      finalBestSolutionConsumer - never null, called only once at the end of the solving process on a consumer thread
      Returns:
      this, never null
    • withFirstInitializedSolutionConsumer

      SolverJobBuilder<Solution_,ProblemId_> withFirstInitializedSolutionConsumer(Consumer<? super Solution_> firstInitializedSolutionConsumer)
      Sets the consumer of the first initialized solution. First initialized solution is the solution at the end of the last phase that immediately precedes the first local search phase. This solution marks the beginning of actual optimization process.
      Parameters:
      firstInitializedSolutionConsumer - never null, called only once before starting the first Local Search phase
      Returns:
      this, never null
    • withSolverJobStartedConsumer

      SolverJobBuilder<Solution_,ProblemId_> withSolverJobStartedConsumer(Consumer<? super Solution_> solverJobStartedConsumer)
      Sets the consumer for when the solver starts its solving process.
      Parameters:
      solverJobStartedConsumer - never null, called only once when the solver is starting the solving process
      Returns:
      this, never null
    • withExceptionHandler

      SolverJobBuilder<Solution_,ProblemId_> withExceptionHandler(BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler)
      Sets the custom exception handler.
      Parameters:
      exceptionHandler - never null, called if an exception or error occurs. If null it defaults to logging the exception as an error.
      Returns:
      this, never null
    • withConfigOverride

      SolverJobBuilder<Solution_,ProblemId_> withConfigOverride(SolverConfigOverride<Solution_> solverConfigOverride)
      Sets the solver config override.
      Parameters:
      solverConfigOverride - never null, allows overriding the default behavior of Solver
      Returns:
      this, never null
    • run

      Submits a planning problem to solve and returns immediately. The planning problem is solved on a solver Thread, as soon as one is available.
      Returns:
      never null