Class DefaultSolverJobBuilder<Solution_,ProblemId_>
java.lang.Object
ai.timefold.solver.core.impl.solver.DefaultSolverJobBuilder<Solution_,ProblemId_>
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotationProblemId_- the ID type of submitted problem, such asLongorUUID.
- All Implemented Interfaces:
SolverJobBuilder<Solution_,ProblemId_>
public final class DefaultSolverJobBuilder<Solution_,ProblemId_>
extends Object
implements SolverJobBuilder<Solution_,ProblemId_>
-
Nested Class Summary
Nested classes/interfaces inherited from interface ai.timefold.solver.core.api.solver.SolverJobBuilder
SolverJobBuilder.FirstInitializedSolutionConsumer<Solution_> -
Constructor Summary
ConstructorsConstructorDescriptionDefaultSolverJobBuilder(DefaultSolverManager<Solution_, ProblemId_> solverManager) -
Method Summary
Modifier and TypeMethodDescription@NonNull SolverJob<Solution_,ProblemId_> run()Submits a planning problem to solve and returns immediately.@NonNull SolverJobBuilder<Solution_,ProblemId_> withBestSolutionConsumer(@NonNull Consumer<? super Solution_> bestSolutionConsumer) Sets the best solution consumer, which may be called multiple times during the solving process.@NonNull SolverJobBuilder<Solution_,ProblemId_> withConfigOverride(@NonNull SolverConfigOverride<Solution_> solverConfigOverride) Sets the solver config override.@NonNull SolverJobBuilder<Solution_,ProblemId_> withExceptionHandler(@NonNull BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler) Sets the custom exception handler.@NonNull SolverJobBuilder<Solution_,ProblemId_> withFinalBestSolutionConsumer(@NonNull 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.@NonNull SolverJobBuilder<Solution_,ProblemId_> withFirstInitializedSolutionConsumer(@NonNull SolverJobBuilder.FirstInitializedSolutionConsumer<? super Solution_> firstInitializedSolutionConsumer) Sets the consumer of the first initialized solution, the beginning of the actual optimization process.@NonNull SolverJobBuilder<Solution_,ProblemId_> withProblemFinder(@NonNull Function<? super ProblemId_, ? extends Solution_> problemFinder) Sets the mapping function to the problem definition.@NonNull SolverJobBuilder<Solution_,ProblemId_> withProblemId(@NonNull ProblemId_ problemId) Sets the problem id.withSolverJobStartedConsumer(Consumer<? super Solution_> solverJobStartedConsumer) Sets the consumer for when the solver starts its solving process.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ai.timefold.solver.core.api.solver.SolverJobBuilder
withFirstInitializedSolutionConsumer, withProblem
-
Constructor Details
-
DefaultSolverJobBuilder
-
-
Method Details
-
withProblemId
Description copied from interface:SolverJobBuilderSets the problem id.- Specified by:
withProblemIdin interfaceSolverJobBuilder<Solution_,ProblemId_> - Parameters:
problemId- a ID for each planning problem. This must be unique.- Returns:
- this
-
withProblemFinder
public @NonNull SolverJobBuilder<Solution_,ProblemId_> withProblemFinder(@NonNull Function<? super ProblemId_, ? extends Solution_> problemFinder) Description copied from interface:SolverJobBuilderSets the mapping function to the problem definition.- Specified by:
withProblemFinderin interfaceSolverJobBuilder<Solution_,ProblemId_> - Parameters:
problemFinder- a function that returns aPlanningSolution, usually with uninitialized planning variables- Returns:
- this
-
withBestSolutionConsumer
public @NonNull SolverJobBuilder<Solution_,ProblemId_> withBestSolutionConsumer(@NonNull Consumer<? super Solution_> bestSolutionConsumer) Description copied from interface:SolverJobBuilderSets the best solution consumer, which may be called multiple times during the solving process.Don't apply any changes to the solution instance while the solver runs. The solver's best solution instance is the same as the one in the event, and any modifications may lead to solver corruption due to its internal reuse.
- Specified by:
withBestSolutionConsumerin interfaceSolverJobBuilder<Solution_,ProblemId_> - Parameters:
bestSolutionConsumer- called multiple times for each new best solution on a consumer thread- Returns:
- this
-
withFinalBestSolutionConsumer
public @NonNull SolverJobBuilder<Solution_,ProblemId_> withFinalBestSolutionConsumer(@NonNull Consumer<? super Solution_> finalBestSolutionConsumer) Description copied from interface:SolverJobBuilderSets the final best solution consumer, which is called at the end of the solving process and returns the final best solution.- Specified by:
withFinalBestSolutionConsumerin interfaceSolverJobBuilder<Solution_,ProblemId_> - Parameters:
finalBestSolutionConsumer- called only once at the end of the solving process on a consumer thread- Returns:
- this
-
withFirstInitializedSolutionConsumer
public @NonNull SolverJobBuilder<Solution_,ProblemId_> withFirstInitializedSolutionConsumer(@NonNull SolverJobBuilder.FirstInitializedSolutionConsumer<? super Solution_> firstInitializedSolutionConsumer) Description copied from interface:SolverJobBuilderSets the consumer of the first initialized solution, the beginning of the actual optimization process. First initialized solution is the solution at the end of the last phase that immediately precedes the first local search phase.- Specified by:
withFirstInitializedSolutionConsumerin interfaceSolverJobBuilder<Solution_,ProblemId_> - Parameters:
firstInitializedSolutionConsumer- called only once before starting the first Local Search phase- Returns:
- this
-
withSolverJobStartedConsumer
public SolverJobBuilder<Solution_,ProblemId_> withSolverJobStartedConsumer(Consumer<? super Solution_> solverJobStartedConsumer) Description copied from interface:SolverJobBuilderSets the consumer for when the solver starts its solving process.- Specified by:
withSolverJobStartedConsumerin interfaceSolverJobBuilder<Solution_,ProblemId_> - Parameters:
solverJobStartedConsumer- never null, called only once when the solver is starting the solving process- Returns:
- this, never null
-
withExceptionHandler
public @NonNull SolverJobBuilder<Solution_,ProblemId_> withExceptionHandler(@NonNull BiConsumer<? super ProblemId_, ? super Throwable> exceptionHandler) Description copied from interface:SolverJobBuilderSets the custom exception handler.- Specified by:
withExceptionHandlerin interfaceSolverJobBuilder<Solution_,ProblemId_> - Parameters:
exceptionHandler- called if an exception or error occurs. If null it defaults to logging the exception as an error.- Returns:
- this
-
withConfigOverride
public @NonNull SolverJobBuilder<Solution_,ProblemId_> withConfigOverride(@NonNull SolverConfigOverride<Solution_> solverConfigOverride) Description copied from interface:SolverJobBuilderSets the solver config override.- Specified by:
withConfigOverridein interfaceSolverJobBuilder<Solution_,ProblemId_> - Parameters:
solverConfigOverride- allows overriding the default behavior ofSolver- Returns:
- this
-
run
Description copied from interface:SolverJobBuilderSubmits a planning problem to solve and returns immediately. The planning problem is solved on a solverThread, as soon as one is available.- Specified by:
runin interfaceSolverJobBuilder<Solution_,ProblemId_>
-