Solution_
- the solution type, the class with the PlanningSolution
annotationProblemId_
- the ID type of a submitted problem, such as Long
or UUID
.public final class DefaultSolverManager<Solution_,ProblemId_> extends Object implements SolverManager<Solution_,ProblemId_>
Modifier and Type | Field and Description |
---|---|
protected org.slf4j.Logger |
logger |
Constructor and Description |
---|
DefaultSolverManager(SolverFactory<Solution_> solverFactory,
SolverManagerConfig solverManagerConfig) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Terminates all solvers, cancels all solver jobs that haven't (re)started yet
and discards all queued
ProblemFactChange s. |
protected ConcurrentMap<Object,DefaultSolverJob<Solution_,ProblemId_>> |
getProblemIdToSolverJobMap() |
SolverFactory<Solution_> |
getSolverFactory() |
SolverStatus |
getSolverStatus(ProblemId_ problemId)
Returns if the
Solver is scheduled to solve, actively solving or not. |
SolverJob<Solution_,ProblemId_> |
solve(ProblemId_ problemId,
Function<? super ProblemId_,? extends Solution_> problemFinder,
Consumer<? super Solution_> finalBestSolutionConsumer,
BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler)
As defined by
SolverManager.solve(Object, Function, Consumer) . |
protected SolverJob<Solution_,ProblemId_> |
solve(ProblemId_ problemId,
Function<? super ProblemId_,? extends Solution_> problemFinder,
Consumer<? super Solution_> bestSolutionConsumer,
Consumer<? super Solution_> finalBestSolutionConsumer,
BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler) |
SolverJob<Solution_,ProblemId_> |
solveAndListen(ProblemId_ problemId,
Function<? super ProblemId_,? extends Solution_> problemFinder,
Consumer<? super Solution_> bestSolutionConsumer,
BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler)
As defined by
SolverManager.solveAndListen(Object, Function, Consumer) . |
void |
terminateEarly(ProblemId_ problemId)
Terminates the solver or cancels the solver job if it hasn't (re)started yet.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
create, create, solve, solve, solve, solve, solveAndListen
public DefaultSolverManager(SolverFactory<Solution_> solverFactory, SolverManagerConfig solverManagerConfig)
public SolverFactory<Solution_> getSolverFactory()
protected ConcurrentMap<Object,DefaultSolverJob<Solution_,ProblemId_>> getProblemIdToSolverJobMap()
public SolverJob<Solution_,ProblemId_> solve(ProblemId_ problemId, Function<? super ProblemId_,? extends Solution_> problemFinder, Consumer<? super Solution_> finalBestSolutionConsumer, BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler)
SolverManager
SolverManager.solve(Object, Function, Consumer)
.solve
in interface SolverManager<Solution_,ProblemId_>
problemId
- never null, a ID for each planning problem. This must be unique.
Use this problemId to terminate
the solver early,
to get the status
or if the problem changes while solving.problemFinder
- never null, function that returns a PlanningSolution
, usually with uninitialized planning
variablesfinalBestSolutionConsumer
- sometimes null, called only once, at the end, on a consumer threadexceptionHandler
- sometimes null, called if an exception or error occurs.
If null it defaults to logging the exception as an error.public SolverJob<Solution_,ProblemId_> solveAndListen(ProblemId_ problemId, Function<? super ProblemId_,? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer, BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler)
SolverManager
SolverManager.solveAndListen(Object, Function, Consumer)
.solveAndListen
in interface SolverManager<Solution_,ProblemId_>
problemId
- never null, a ID for each planning problem. This must be unique.
Use this problemId to terminate
the solver early,
to get the status
or if the problem changes while solving.problemFinder
- never null, function that returns a PlanningSolution
, usually with uninitialized planning
variablesbestSolutionConsumer
- never null, called multiple times, on a consumer threadexceptionHandler
- sometimes null, called if an exception or error occurs.
If null it defaults to logging the exception as an error.protected SolverJob<Solution_,ProblemId_> solve(ProblemId_ problemId, Function<? super ProblemId_,? extends Solution_> problemFinder, Consumer<? super Solution_> bestSolutionConsumer, Consumer<? super Solution_> finalBestSolutionConsumer, BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler)
public SolverStatus getSolverStatus(ProblemId_ problemId)
SolverManager
Solver
is scheduled to solve, actively solving or not.
Returns SolverStatus.NOT_SOLVING
if the solver already terminated or if the problemId was never added.
To distinguish between both cases, use SolverJob.getSolverStatus()
instead.
Here, that distinction is not supported because it would cause a memory leak.
getSolverStatus
in interface SolverManager<Solution_,ProblemId_>
problemId
- never null, a value given to SolverManager.solve(Object, Function, Consumer)
or SolverManager.solveAndListen(Object, Function, Consumer)
public void terminateEarly(ProblemId_ problemId)
SolverManager
Does nothing if the solver already terminated or the problemId was never added.
To distinguish between both cases, use SolverJob.terminateEarly()
instead.
Here, that distinction is not supported because it would cause a memory leak.
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.
terminateEarly
in interface SolverManager<Solution_,ProblemId_>
problemId
- never null, a value given to SolverManager.solve(Object, Function, Consumer)
or SolverManager.solveAndListen(Object, Function, Consumer)
public void close()
SolverManager
ProblemFactChange
s.
Releases all thread pool resources.
No new planning problems can be submitted after calling this method.
close
in interface AutoCloseable
close
in interface SolverManager<Solution_,ProblemId_>
Copyright © 2006–2020 JBoss by Red Hat. All rights reserved.