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
ThisAbstractOptimizer
is 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 Archive
archive
protected IndividualCompleter
completer
protected Control
control
protected Iteration
iteration
protected Set<OptimizerIterationListener>
iterationListeners
protected boolean
optimizing
protected Population
population
protected Set<OptimizerStateListener>
stateListeners
-
Constructor Summary
Constructors Constructor Description AbstractOptimizer(Population population, Archive archive, IndividualCompleter completer, Control control, Iteration iteration)
Constructs anAbstractOptimizer
with aPopulation
, anArchive
, anIndividualFactory
, and aIndividualCompleter
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addOptimizerIterationListener(OptimizerIterationListener listener)
Adds anOptimizerIterationListener
to this optimizer.void
addOptimizerStateListener(OptimizerStateListener listener)
Adds anOptimizerStateListener
to this optimizer.int
getIteration()
Return the current iteration.protected void
injectListeners(Set<OptimizerStateListener> stateListeners, Set<OptimizerIterationListener> iterationListeners)
boolean
isRunning()
Returnstrue
if theOptimizer
is running.protected void
nextIteration()
Call this method if a new iteration started.void
removeOptimizerIterationListener(OptimizerIterationListener listener)
Removes anOptimizerIterationListener
from this optimizer.void
removeOptimizerStateListener(OptimizerStateListener listener)
Removes anOptimizerStateListener
from this optimizer.void
startOptimization()
This method is called once the optimization process has started.void
stopOptimization()
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 anAbstractOptimizer
with 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:Optimizer
Return the current iteration.- Specified by:
getIteration
in interfaceOptimizer
- Returns:
- the current iteration
-
isRunning
public boolean isRunning()
Description copied from interface:Optimizer
Returnstrue
if theOptimizer
is running.
-
nextIteration
protected void nextIteration() throws TerminationException, StopException
Call 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:Optimizer
This method is called once the optimization process has started.- Specified by:
startOptimization
in interfaceOptimizer
-
stopOptimization
public void stopOptimization()
Description copied from interface:Optimizer
This method is called once the optimization process has stopped.- Specified by:
stopOptimization
in interfaceOptimizer
-
addOptimizerIterationListener
public void addOptimizerIterationListener(OptimizerIterationListener listener)
Description copied from interface:Optimizer
Adds anOptimizerIterationListener
to this optimizer.- Specified by:
addOptimizerIterationListener
in 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:Optimizer
Adds anOptimizerStateListener
to this optimizer.- Specified by:
addOptimizerStateListener
in 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:Optimizer
Removes anOptimizerIterationListener
from this optimizer.- Specified by:
removeOptimizerIterationListener
in 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:Optimizer
Removes anOptimizerStateListener
from this optimizer.- Specified by:
removeOptimizerStateListener
in interfaceOptimizer
- Parameters:
listener
- the OptimizerStateListener to remove- See Also:
Optimizer.addOptimizerStateListener(org.opt4j.core.optimizer.OptimizerStateListener)
-
-