Solution_
- the solution type, the class with the PlanningSolution
annotationpublic class PartitionSolver<Solution_> extends AbstractSolver<Solution_>
Modifier and Type | Field and Description |
---|---|
protected DefaultSolverScope<Solution_> |
solverScope |
bestSolutionRecaller, phaseLifecycleSupport, phaseList, solverEventSupport, termination
Constructor and Description |
---|
PartitionSolver(BestSolutionRecaller<Solution_> bestSolutionRecaller,
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_>> problemFactChanges)
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. |
long |
getScoreCalculationCount() |
InnerScoreDirectorFactory<Solution_> |
getScoreDirectorFactory()
|
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.
|
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 DefaultSolverScope<Solution_> solverScope
public PartitionSolver(BestSolutionRecaller<Solution_> bestSolutionRecaller, Termination termination, List<Phase<Solution_>> phaseList, DefaultSolverScope<Solution_> solverScope)
public InnerScoreDirectorFactory<Solution_> getScoreDirectorFactory()
Solver
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.
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.getConstraintMatchTotals()
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_>> problemFactChanges)
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
.
problemFactChanges
- 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 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 solvingStarted(DefaultSolverScope<Solution_> solverScope)
solvingStarted
in class AbstractSolver<Solution_>
public void solvingEnded(DefaultSolverScope<Solution_> solverScope)
solvingEnded
in class AbstractSolver<Solution_>
public long getScoreCalculationCount()
Copyright © 2006–2019 JBoss by Red Hat. All rights reserved.