Class DefaultSolver<Solution_>
- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotation
- All Implemented Interfaces:
Solver<Solution_>
Solver
.- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected BasicPlumbingTermination<Solution_>
protected EnvironmentMode
protected RandomFactory
protected final SolverScope<Solution_>
protected final AtomicBoolean
Fields inherited from class org.optaplanner.core.impl.solver.AbstractSolver
bestSolutionRecaller, logger, phaseList, solverTermination
-
Constructor Summary
ConstructorDescriptionDefaultSolver
(EnvironmentMode environmentMode, RandomFactory randomFactory, BestSolutionRecaller<Solution_> bestSolutionRecaller, BasicPlumbingTermination<Solution_> basicPlumbingTermination, Termination<Solution_> termination, List<Phase<Solution_>> phaseList, SolverScope<Solution_> solverScope, String moveThreadCountDescription) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addProblemChange
(ProblemChange<Solution_> problemChange) Schedules aProblemChange
to be processed.void
addProblemChanges
(List<ProblemChange<Solution_>> problemChangeList) Schedules multipleProblemChange
s to be processed.boolean
addProblemFactChange
(ProblemFactChange<Solution_> problemFactChange) This method is deprecated.boolean
addProblemFactChanges
(List<ProblemFactChange<Solution_>> problemFactChangeList) This method is deprecated.long
boolean
Checks if all scheduledProblemChange
s have been processed.boolean
This method is deprecated.boolean
This method is thread-safe.boolean
This method is thread-safe.void
outerSolvingEnded
(SolverScope<Solution_> solverScope) void
outerSolvingStarted
(SolverScope<Solution_> solverScope) void
setMonitorTagMap
(Map<String, String> monitorTagMap) final Solution_
Solves the planning problem and returns the best solution encountered (which might or might not be optimal, feasible or even initialized).void
solvingEnded
(SolverScope<Solution_> solverScope) void
solvingStarted
(SolverScope<Solution_> solverScope) boolean
Notifies the solver that it should stop at its earliest convenience.Methods inherited from class org.optaplanner.core.impl.solver.AbstractSolver
addEventListener, addPhaseLifecycleListener, getBestSolutionRecaller, getPhaseList, phaseEnded, phaseStarted, removeEventListener, removePhaseLifecycleListener, runPhases, solvingError, stepEnded, stepStarted
-
Field Details
-
environmentMode
-
randomFactory
-
basicPlumbingTermination
-
solving
-
solverScope
-
-
Constructor Details
-
DefaultSolver
public DefaultSolver(EnvironmentMode environmentMode, RandomFactory randomFactory, BestSolutionRecaller<Solution_> bestSolutionRecaller, BasicPlumbingTermination<Solution_> basicPlumbingTermination, Termination<Solution_> termination, List<Phase<Solution_>> phaseList, SolverScope<Solution_> solverScope, String moveThreadCountDescription)
-
-
Method Details
-
getEnvironmentMode
-
getRandomFactory
-
getScoreDirectorFactory
-
getSolverScope
-
getTimeMillisSpent
public long getTimeMillisSpent() -
isSolving
public boolean isSolving()Description copied from interface:Solver
This method is thread-safe.- Returns:
- true if the
Solver.solve(Solution_)
method is still running.
-
terminateEarly
public boolean terminateEarly()Description copied from interface:Solver
Notifies the solver that it should stop at its earliest convenience. This method returns immediately, but it takes an undetermined time for theSolver.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)
.- Returns:
- true if successful, false if was already terminating or terminated
- See Also:
-
isTerminateEarly
public boolean isTerminateEarly()Description copied from interface:Solver
This method is thread-safe.- Returns:
- true if terminateEarly has been called since the
Solver
started. - See Also:
-
addProblemFactChange
Description copied from interface:Solver
This method is deprecated. Schedules aProblemFactChange
to be processed.As a side-effect, this restarts the
Solver
, effectively resetting all terminations, but notSolver.terminateEarly()
.This method is thread-safe. Follows specifications of
BlockingQueue.add(Object)
with by default a capacity ofInteger.MAX_VALUE
.- Parameters:
problemFactChange
- never null- Returns:
- true (as specified by
Collection.add(E)
) - See Also:
-
addProblemFactChanges
Description copied from interface:Solver
This method is deprecated. Schedules multipleProblemFactChange
s to be processed.As a side-effect, this restarts the
Solver
, effectively resetting all terminations, but notSolver.terminateEarly()
.This method is thread-safe. Follows specifications of
Collection.addAll(Collection)
with by default a capacity ofInteger.MAX_VALUE
.- Parameters:
problemFactChangeList
- never null- Returns:
- true (as specified by
Collection.add(E)
) - See Also:
-
addProblemChange
Description copied from interface:Solver
Schedules aProblemChange
to be processed.As a side effect, this restarts the
Solver
, effectively resetting allTermination
s, but notSolver.terminateEarly()
.This method is thread-safe. Follows specifications of
BlockingQueue.add(Object)
with by default a capacity ofInteger.MAX_VALUE
.To learn more about problem change semantics, please refer to the
ProblemChange
Javadoc.- Parameters:
problemChange
- never null- See Also:
-
addProblemChanges
Description copied from interface:Solver
Schedules multipleProblemChange
s to be processed.As a side effect, this restarts the
Solver
, effectively resetting allTermination
s, but notSolver.terminateEarly()
.This method is thread-safe. Follows specifications of
BlockingQueue.add(Object)
with by default a capacity ofInteger.MAX_VALUE
.To learn more about problem change semantics, please refer to the
ProblemChange
Javadoc.- Parameters:
problemChangeList
- never null- See Also:
-
isEveryProblemChangeProcessed
public boolean isEveryProblemChangeProcessed()Description copied from interface:Solver
Checks if all scheduledProblemChange
s have been processed.This method is thread-safe.
- Returns:
- true if there are no
ProblemChange
s left to do
-
isEveryProblemFactChangeProcessed
public boolean isEveryProblemFactChangeProcessed()Description copied from interface:Solver
This method is deprecated. Checks if all scheduledProblemFactChange
s have been processed.This method is thread-safe.
- Returns:
- true if there are no
ProblemFactChange
s left to do
-
setMonitorTagMap
-
solve
Description copied from interface:Solver
Solves the planning problem and returns the best solution encountered (which might or might not be optimal, feasible or even initialized).It can take seconds, minutes, even hours or days before this method returns, depending on the termination configuration. To terminate a
Solver
early, callSolver.terminateEarly()
.- Parameters:
problem
- never null, aPlanningSolution
, usually its planning variables are uninitialized- Returns:
- never null, but it can return the original, uninitialized
PlanningSolution
with a nullScore
. - See Also:
-
outerSolvingStarted
-
solvingStarted
- Overrides:
solvingStarted
in classAbstractSolver<Solution_>
-
solvingEnded
- Overrides:
solvingEnded
in classAbstractSolver<Solution_>
-
outerSolvingEnded
-