Solution_
- the solution type, the class with the PlanningSolution
annotationpublic class DefaultSolver<Solution_> extends AbstractSolver<Solution_>
Solver
.Solver
,
AbstractSolver
Modifier and Type | Field and Description |
---|---|
protected BasicPlumbingTermination |
basicPlumbingTermination |
protected EnvironmentMode |
environmentMode |
protected org.slf4j.Logger |
logger |
protected RandomFactory |
randomFactory |
protected DefaultSolverScope<Solution_> |
solverScope |
protected AtomicBoolean |
solving |
bestSolutionRecaller, phaseLifecycleSupport, phaseList, solverEventSupport, termination
Constructor and Description |
---|
DefaultSolver(EnvironmentMode environmentMode,
RandomFactory randomFactory,
BasicPlumbingTermination basicPlumbingTermination,
Termination termination,
BestSolutionRecaller<Solution_> bestSolutionRecaller,
List<Phase<Solution_>> phaseList,
DefaultSolverScope<Solution_> solverScope) |
Modifier and Type | Method and Description |
---|---|
boolean |
addProblemFactChange(ProblemFactChange<Solution_> problemFactChange)
Schedules a
ProblemFactChange to be processed. |
Score |
getBestScore()
Returns the
Score of the Solver.getBestSolution() . |
Solution_ |
getBestSolution()
The best solution is the
best solution found during solving:
it might or might not be optimal, feasible or even initialized. |
BestSolutionRecaller<Solution_> |
getBestSolutionRecaller() |
EnvironmentMode |
getEnvironmentMode() |
List<Phase<Solution_>> |
getPhaseList() |
RandomFactory |
getRandomFactory() |
InnerScoreDirectorFactory<Solution_> |
getScoreDirectorFactory()
|
DefaultSolverScope<Solution_> |
getSolverScope() |
long |
getTimeMillisSpent() |
boolean |
isEveryProblemFactChangeProcessed()
Checks if all scheduled
ProblemFactChange s have been processed. |
boolean |
isSolving()
This method is thread-safe.
|
boolean |
isTerminateEarly()
This method is thread-safe.
|
void |
outerSolvingEnded(DefaultSolverScope<Solution_> solverScope) |
void |
outerSolvingStarted(DefaultSolverScope<Solution_> solverScope) |
Solution_ |
solve(Solution_ planningProblem)
Solves the planning problem and returns the best solution encountered
(which might or might not be optimal, feasible or even initialized).
|
void |
solvingEnded(DefaultSolverScope<Solution_> solverScope) |
void |
solvingStarted(DefaultSolverScope<Solution_> solverScope) |
boolean |
terminateEarly()
Notifies the solver that it should stop at its earliest convenience.
|
addEventListener, addPhaseLifecycleListener, removeEventListener, removePhaseLifecycleListener, runPhases
protected final transient org.slf4j.Logger logger
protected EnvironmentMode environmentMode
protected RandomFactory randomFactory
protected BasicPlumbingTermination basicPlumbingTermination
protected final AtomicBoolean solving
protected final DefaultSolverScope<Solution_> solverScope
public DefaultSolver(EnvironmentMode environmentMode, RandomFactory randomFactory, BasicPlumbingTermination basicPlumbingTermination, Termination termination, BestSolutionRecaller<Solution_> bestSolutionRecaller, List<Phase<Solution_>> phaseList, DefaultSolverScope<Solution_> solverScope)
public EnvironmentMode getEnvironmentMode()
public RandomFactory getRandomFactory()
public InnerScoreDirectorFactory<Solution_> getScoreDirectorFactory()
Solver
public BestSolutionRecaller<Solution_> getBestSolutionRecaller()
public DefaultSolverScope<Solution_> getSolverScope()
public Solution_ getBestSolution()
Solver
best solution
found during solving:
it might or might not be optimal, feasible or even initialized.
The #solve(Solution_)
method also returns the best solution,
but this method is useful in rare asynchronous situations (although
SolverEventListener.bestSolutionChanged(BestSolutionChangedEvent)
is often more appropriate).
This method is thread-safe.
PlanningSolution
with a Score
null.public Score getBestScore()
Solver
Score
of the Solver.getBestSolution()
.
This is useful for generic code, which doesn't know the type of the PlanningSolution
to retrieve the Score
from the Solver.getBestSolution()
easily.
PlanningSolution
is still uninitializedpublic long getTimeMillisSpent()
public boolean isSolving()
Solver
#solve(Solution_)
method is still running.public boolean terminateEarly()
Solver
#solve(Solution_)
to actually return.
This method is thread-safe.
Solver.isTerminateEarly()
,
Future.cancel(boolean)
public boolean isTerminateEarly()
Solver
Solver
started.Future.isCancelled()
public boolean addProblemFactChange(ProblemFactChange<Solution_> problemFactChange)
Solver
ProblemFactChange
to be processed.
As a side-effect, this restarts the Solver
, effectively resetting all Termination
s,
but not Solver.terminateEarly()
.
This method is thread-safe.
Follows specifications of BlockingQueue.add(Object)
with by default
a capacity of Integer.MAX_VALUE
.
problemFactChange
- never nullCollection.add(E)
)public boolean isEveryProblemFactChangeProcessed()
Solver
ProblemFactChange
s have been processed.
This method is thread-safe.
ProblemFactChange
s left to dopublic final Solution_ solve(Solution_ planningProblem)
Solver
It can take seconds, minutes, even hours or days before this method returns,
depending on the Termination
configuration.
To terminate a Solver
early, call Solver.terminateEarly()
.
planningProblem
- never null, usually its planning variables are uninitializedPlanningSolution
with a Score
null.Solver.terminateEarly()
public void outerSolvingStarted(DefaultSolverScope<Solution_> solverScope)
public void solvingStarted(DefaultSolverScope<Solution_> solverScope)
solvingStarted
in class AbstractSolver<Solution_>
public void solvingEnded(DefaultSolverScope<Solution_> solverScope)
solvingEnded
in class AbstractSolver<Solution_>
public void outerSolvingEnded(DefaultSolverScope<Solution_> solverScope)
Copyright © 2006–2016 JBoss by Red Hat. All rights reserved.