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, logger, 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
ProblemFactChanges 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()
Useful to reuse the
Score calculation (for example in a UI)
and to explain the Score to the user
with the ConstraintMatchTotal and Indictment API. |
long |
getTimeMillisSpent()
Returns the amount of milliseconds spent solving since the last start.
|
boolean |
isEveryProblemFactChangeProcessed()
Checks if all scheduled
ProblemFactChanges 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, runPhasesprotected final DefaultSolverScope<Solution_> solverScope
public PartitionSolver(BestSolutionRecaller<Solution_> bestSolutionRecaller, Termination termination, List<Phase<Solution_>> phaseList, DefaultSolverScope<Solution_> solverScope)
public InnerScoreDirectorFactory<Solution_> getScoreDirectorFactory()
SolverScore calculation (for example in a UI)
and to explain the Score to the user
with the ConstraintMatchTotal and Indictment API.public Solution_ getBestSolution()
Solverbest 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()
SolverScore 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()
SolverSolver.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 SolverFactory.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()
SolverSolver.solve(Solution_) method is still running.public boolean terminateEarly()
SolverSolver.solve(Solution_) to actually return.
If the solver is running in daemon mode, this is the only way to terminate it normally.
This method is thread-safe.
It can only be called from a different thread
because the original thread is still calling Solver.solve(Object).
Solver.isTerminateEarly(),
Future.cancel(boolean)public boolean isTerminateEarly()
SolverSolver started.Future.isCancelled()public boolean addProblemFactChange(ProblemFactChange<Solution_> problemFactChange)
SolverProblemFactChange to be processed.
As a side-effect, this restarts the Solver, effectively resetting all Terminations,
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)
SolverProblemFactChanges to be processed.
As a side-effect, this restarts the Solver, effectively resetting all Terminations,
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()
SolverProblemFactChanges have been processed.
This method is thread-safe.
ProblemFactChanges 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, a PlanningSolution, usually its planning variables are uninitializedPlanningSolution with a null Score.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–2021 JBoss by Red Hat. All rights reserved.