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,
BestSolutionRecaller<Solution_> bestSolutionRecaller,
BasicPlumbingTermination basicPlumbingTermination,
Termination termination,
List<Phase<Solution_>> phaseList,
DefaultSolverScope<Solution_> solverScope) |
Modifier and Type | Method and Description |
---|---|
boolean |
addProblemFactChange(ProblemFactChange<Solution_> problemFactChange)
Schedules a
ProblemFactChange to be processed. |
boolean |
addProblemFactChanges(List<ProblemFactChange<Solution_>> problemFactChangeList)
Schedules multiple
ProblemFactChange s to be processed. |
String |
explainBestScore()
Returns a diagnostic text that explains the
Solver.getBestSolution() through the ConstraintMatch API
to identify which constraints or planning entities cause that Solver.getBestScore() quality. |
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()
Returns the amount of milliseconds spent solving since the last start.
|
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_ problem)
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, BestSolutionRecaller<Solution_> bestSolutionRecaller, BasicPlumbingTermination basicPlumbingTermination, Termination termination, 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 Solver.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.
Solver.solve(Object)
hasn't been called yet),
but it can return the uninitialized 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.
This method is thread-safe.
PlanningSolution
is still uninitializedpublic String explainBestScore()
Solver
Solver.getBestSolution()
through the ConstraintMatch
API
to identify which constraints or planning entities cause that Solver.getBestScore()
quality.
In case of an infeasible
solution,
this can help diagnose the cause of that.
Do not parse this string.
Instead, to provide this information in a UI or a service, use Solver.getScoreDirectorFactory()
to retrieve ScoreDirector.getConstraintMatchTotalMap()
and ScoreDirector.getIndictmentMap()
and convert those into a domain specific API.
This method is thread-safe.
Solver.getBestScore()
returns nullScoreDirector.explainScore()
public long getTimeMillisSpent()
Solver
A Solver.addProblemFactChange(ProblemFactChange)
triggers a restart which resets this time.
This method is thread-safe.
public boolean isSolving()
Solver
Solver.solve(Solution_)
method is still running.public boolean terminateEarly()
Solver
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)
)Solver.addProblemFactChanges(List)
public boolean addProblemFactChanges(List<ProblemFactChange<Solution_>> problemFactChangeList)
Solver
ProblemFactChange
s 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 Collection.addAll(Collection)
with by default
a capacity of Integer.MAX_VALUE
.
problemFactChangeList
- never nullCollection.add(E)
)Solver.addProblemFactChange(ProblemFactChange)
public boolean isEveryProblemFactChangeProcessed()
Solver
ProblemFactChange
s have been processed.
This method is thread-safe.
ProblemFactChange
s left to dopublic final Solution_ solve(Solution_ problem)
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()
.
problem
- 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–2019 JBoss by Red Hat. All rights reserved.