Package org.opt4j.core.optimizer
Class AbstractOptimizer
- java.lang.Object
-
- org.opt4j.core.optimizer.AbstractOptimizer
-
- All Implemented Interfaces:
Optimizer
- Direct Known Subclasses:
DifferentialEvolution,EvolutionaryAlgorithm,MOPSO,RandomSearch,SimulatedAnnealing
public abstract class AbstractOptimizer extends Object implements Optimizer
ThisAbstractOptimizeris an abstract implementation of a population-basedOptimizer. All population based optimizers can be derived from this class.
-
-
Field Summary
Fields Modifier and Type Field Description protected Archivearchiveprotected IndividualCompletercompleterprotected Controlcontrolprotected Iterationiterationprotected Set<OptimizerIterationListener>iterationListenersprotected booleanoptimizingprotected Populationpopulationprotected Set<OptimizerStateListener>stateListeners
-
Constructor Summary
Constructors Constructor Description AbstractOptimizer(Population population, Archive archive, IndividualCompleter completer, Control control, Iteration iteration)Constructs anAbstractOptimizerwith aPopulation, anArchive, anIndividualFactory, and aIndividualCompleter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddOptimizerIterationListener(OptimizerIterationListener listener)Adds anOptimizerIterationListenerto this optimizer.voidaddOptimizerStateListener(OptimizerStateListener listener)Adds anOptimizerStateListenerto this optimizer.intgetIteration()Return the current iteration.protected voidinjectListeners(Set<OptimizerStateListener> stateListeners, Set<OptimizerIterationListener> iterationListeners)booleanisRunning()Returnstrueif theOptimizeris running.protected voidnextIteration()Call this method if a new iteration started.voidremoveOptimizerIterationListener(OptimizerIterationListener listener)Removes anOptimizerIterationListenerfrom this optimizer.voidremoveOptimizerStateListener(OptimizerStateListener listener)Removes anOptimizerStateListenerfrom this optimizer.voidstartOptimization()This method is called once the optimization process has started.voidstopOptimization()This method is called once the optimization process has stopped.
-
-
-
Field Detail
-
iteration
protected final Iteration iteration
-
population
protected final Population population
-
archive
protected final Archive archive
-
completer
protected final IndividualCompleter completer
-
control
protected final Control control
-
stateListeners
protected final Set<OptimizerStateListener> stateListeners
-
iterationListeners
protected final Set<OptimizerIterationListener> iterationListeners
-
optimizing
protected boolean optimizing
-
-
Constructor Detail
-
AbstractOptimizer
public AbstractOptimizer(Population population, Archive archive, IndividualCompleter completer, Control control, Iteration iteration)
Constructs anAbstractOptimizerwith aPopulation, anArchive, anIndividualFactory, and aIndividualCompleter.- Parameters:
population- the specified populationarchive- the specified archivecompleter- the specified completercontrol- the controliteration- the iteration counter
-
-
Method Detail
-
injectListeners
@Inject protected void injectListeners(Set<OptimizerStateListener> stateListeners, Set<OptimizerIterationListener> iterationListeners)
-
getIteration
public int getIteration()
Description copied from interface:OptimizerReturn the current iteration.- Specified by:
getIterationin interfaceOptimizer- Returns:
- the current iteration
-
isRunning
public boolean isRunning()
Description copied from interface:OptimizerReturnstrueif theOptimizeris running.
-
nextIteration
protected void nextIteration() throws TerminationException, StopExceptionCall this method if a new iteration started.- Throws:
StopException- if the optimization is stoppedTerminationException- if the optimization is terminated
-
startOptimization
public void startOptimization()
Description copied from interface:OptimizerThis method is called once the optimization process has started.- Specified by:
startOptimizationin interfaceOptimizer
-
stopOptimization
public void stopOptimization()
Description copied from interface:OptimizerThis method is called once the optimization process has stopped.- Specified by:
stopOptimizationin interfaceOptimizer
-
addOptimizerIterationListener
public void addOptimizerIterationListener(OptimizerIterationListener listener)
Description copied from interface:OptimizerAdds anOptimizerIterationListenerto this optimizer.- Specified by:
addOptimizerIterationListenerin interfaceOptimizer- Parameters:
listener- the OptimizerIterationListener to add- See Also:
Optimizer.removeOptimizerIterationListener(org.opt4j.core.optimizer.OptimizerIterationListener)
-
addOptimizerStateListener
public void addOptimizerStateListener(OptimizerStateListener listener)
Description copied from interface:OptimizerAdds anOptimizerStateListenerto this optimizer.- Specified by:
addOptimizerStateListenerin interfaceOptimizer- Parameters:
listener- the OptimizerStateListener to add- See Also:
Optimizer.removeOptimizerStateListener(org.opt4j.core.optimizer.OptimizerStateListener)
-
removeOptimizerIterationListener
public void removeOptimizerIterationListener(OptimizerIterationListener listener)
Description copied from interface:OptimizerRemoves anOptimizerIterationListenerfrom this optimizer.- Specified by:
removeOptimizerIterationListenerin interfaceOptimizer- Parameters:
listener- the OptimizerIterationListener to remove- See Also:
Optimizer.addOptimizerIterationListener(org.opt4j.core.optimizer.OptimizerIterationListener)
-
removeOptimizerStateListener
public void removeOptimizerStateListener(OptimizerStateListener listener)
Description copied from interface:OptimizerRemoves anOptimizerStateListenerfrom this optimizer.- Specified by:
removeOptimizerStateListenerin interfaceOptimizer- Parameters:
listener- the OptimizerStateListener to remove- See Also:
Optimizer.addOptimizerStateListener(org.opt4j.core.optimizer.OptimizerStateListener)
-
-