Package org.optaplanner.core.impl.solver
Class AbstractSolver<Solution_>
- java.lang.Object
-
- org.optaplanner.core.impl.solver.AbstractSolver<Solution_>
-
- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotation
- All Implemented Interfaces:
Solver<Solution_>
- Direct Known Subclasses:
DefaultSolver
,PartitionSolver
public abstract class AbstractSolver<Solution_> extends Object implements Solver<Solution_>
Common code betweenDefaultSolver
and child solvers (such asPartitionSolver
.Do not create a new child
Solver
to implement a new heuristic or metaheuristic, just use a newPhase
for that.- See Also:
Solver
,DefaultSolver
-
-
Field Summary
Fields Modifier and Type Field Description protected BestSolutionRecaller<Solution_>
bestSolutionRecaller
protected org.slf4j.Logger
logger
protected PhaseLifecycleSupport<Solution_>
phaseLifecycleSupport
protected List<Phase<Solution_>>
phaseList
protected SolverEventSupport<Solution_>
solverEventSupport
protected Termination
termination
-
Constructor Summary
Constructors Constructor Description AbstractSolver(BestSolutionRecaller<Solution_> bestSolutionRecaller, Termination termination, List<Phase<Solution_>> phaseList)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEventListener(SolverEventListener<Solution_> eventListener)
void
addPhaseLifecycleListener(PhaseLifecycleListener<Solution_> phaseLifecycleListener)
Add aPhaseLifecycleListener
that is notified ofSolverLifecycleListener.solvingStarted(DefaultSolverScope)
solving} events and also of thephase
and thePhaseLifecycleListener.stepStarted(AbstractStepScope)
step} starting/ending events of all phases.void
removeEventListener(SolverEventListener<Solution_> eventListener)
void
removePhaseLifecycleListener(PhaseLifecycleListener<Solution_> phaseLifecycleListener)
protected void
runPhases(DefaultSolverScope<Solution_> solverScope)
void
solvingEnded(DefaultSolverScope<Solution_> solverScope)
void
solvingStarted(DefaultSolverScope<Solution_> solverScope)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.optaplanner.core.api.solver.Solver
addProblemFactChange, addProblemFactChanges, explainBestScore, getBestScore, getBestSolution, getScoreDirectorFactory, getTimeMillisSpent, isEveryProblemFactChangeProcessed, isSolving, isTerminateEarly, solve, terminateEarly
-
-
-
-
Field Detail
-
logger
protected final transient org.slf4j.Logger logger
-
solverEventSupport
protected final SolverEventSupport<Solution_> solverEventSupport
-
phaseLifecycleSupport
protected final PhaseLifecycleSupport<Solution_> phaseLifecycleSupport
-
bestSolutionRecaller
protected final BestSolutionRecaller<Solution_> bestSolutionRecaller
-
termination
protected final Termination termination
-
-
Constructor Detail
-
AbstractSolver
public AbstractSolver(BestSolutionRecaller<Solution_> bestSolutionRecaller, Termination termination, List<Phase<Solution_>> phaseList)
-
-
Method Detail
-
solvingStarted
public void solvingStarted(DefaultSolverScope<Solution_> solverScope)
-
runPhases
protected void runPhases(DefaultSolverScope<Solution_> solverScope)
-
solvingEnded
public void solvingEnded(DefaultSolverScope<Solution_> solverScope)
-
addEventListener
public void addEventListener(SolverEventListener<Solution_> eventListener)
- Specified by:
addEventListener
in interfaceSolver<Solution_>
- Parameters:
eventListener
- never null
-
removeEventListener
public void removeEventListener(SolverEventListener<Solution_> eventListener)
- Specified by:
removeEventListener
in interfaceSolver<Solution_>
- Parameters:
eventListener
- never null
-
addPhaseLifecycleListener
public void addPhaseLifecycleListener(PhaseLifecycleListener<Solution_> phaseLifecycleListener)
Add aPhaseLifecycleListener
that is notified ofSolverLifecycleListener.solvingStarted(DefaultSolverScope)
solving} events and also of thephase
and thePhaseLifecycleListener.stepStarted(AbstractStepScope)
step} starting/ending events of all phases.To get notified for only 1 phase, use
Phase.addPhaseLifecycleListener(PhaseLifecycleListener)
instead.- Parameters:
phaseLifecycleListener
- never null
-
removePhaseLifecycleListener
public void removePhaseLifecycleListener(PhaseLifecycleListener<Solution_> phaseLifecycleListener)
- Parameters:
phaseLifecycleListener
- never null- See Also:
addPhaseLifecycleListener(PhaseLifecycleListener)
-
-