Class GeneticAlgorithm
java.lang.Object
org.moeaframework.algorithm.AbstractAlgorithm
org.moeaframework.algorithm.AbstractEvolutionaryAlgorithm
org.moeaframework.algorithm.single.SingleObjectiveEvolutionaryAlgorithm
org.moeaframework.algorithm.single.GeneticAlgorithm
- All Implemented Interfaces:
Extensible
,Algorithm
,Configurable
,EvolutionaryAlgorithm
,Stateful
Single-objective genetic algorithm (GA) implementation with elitism. A single elite individual is retained in each
generation.
References:
- John Holland. "Adaptation in Natural and Artificial Systems." MIT Press, ISBN: 9780262082136.
-
Field Summary
Fields inherited from class org.moeaframework.algorithm.single.SingleObjectiveEvolutionaryAlgorithm
comparator
Fields inherited from class org.moeaframework.algorithm.AbstractAlgorithm
initialized, numberOfEvaluations, problem, terminated
-
Constructor Summary
ConstructorDescriptionGeneticAlgorithm
(Problem problem) Constructs a new instance of the genetic algorithm (GA) with default settings.GeneticAlgorithm
(Problem problem, int initialPopulationSize, AggregateObjectiveComparator comparator, Initialization initialization, Variation variation) Constructs a new instance of the genetic algorithm (GA). -
Method Summary
Modifier and TypeMethodDescriptionReturns the current best-known result.void
Performs any initialization that is required by this algorithm.void
iterate()
Performs one iteration of the algorithm.void
loadState
(ObjectInputStream stream) Loads the state of this object from the stream.void
setComparator
(AggregateObjectiveComparator comparator) Sets the aggregate objective comparator that scalarizes multiple objectives into a single fitness value.void
setVariation
(Variation variation) Replaces the variation operator to be used by this algorithm.void
Update the elite solution.Methods inherited from class org.moeaframework.algorithm.single.SingleObjectiveEvolutionaryAlgorithm
applyConfiguration, getComparator, getConfiguration, setInitialPopulationSize
Methods inherited from class org.moeaframework.algorithm.AbstractEvolutionaryAlgorithm
getArchive, getInitialization, getInitialPopulationSize, getPopulation, getVariation, saveState, setArchive, setInitialization, setPopulation
Methods inherited from class org.moeaframework.algorithm.AbstractAlgorithm
assertNotInitialized, evaluate, getExtensions, getNumberOfEvaluations, getProblem, isInitialized, isTerminated, step, terminate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.moeaframework.core.Algorithm
evaluate, evaluateAll, evaluateAll, getNumberOfEvaluations, getProblem, isInitialized, isTerminated, run, run, step, terminate
Methods inherited from interface org.moeaframework.algorithm.extension.Extensible
addExtension, getExtensions, removeExtension
-
Constructor Details
-
GeneticAlgorithm
Constructs a new instance of the genetic algorithm (GA) with default settings.- Parameters:
problem
- the problem
-
GeneticAlgorithm
public GeneticAlgorithm(Problem problem, int initialPopulationSize, AggregateObjectiveComparator comparator, Initialization initialization, Variation variation) Constructs a new instance of the genetic algorithm (GA).- Parameters:
problem
- the probleminitialPopulationSize
- the initial population sizecomparator
- the aggregate objective comparatorinitialization
- the initialization methodvariation
- the variation operator
-
-
Method Details
-
initialize
public void initialize()Description copied from interface:Algorithm
Performs any initialization that is required by this algorithm. This method should only be called once, though the specific implementation may choose to no-op or throwAlgorithmInitializationException
if called multiple times.Implementations should always call
super.initialize()
to ensure the algorithm is initialized correctly.- Specified by:
initialize
in interfaceAlgorithm
- Overrides:
initialize
in classAbstractEvolutionaryAlgorithm
-
iterate
public void iterate()Description copied from class:AbstractAlgorithm
Performs one iteration of the algorithm. This method should be overridden by implementations to perform each logical iteration of the algorithm.- Specified by:
iterate
in classAbstractAlgorithm
-
updateEliteSolution
public void updateEliteSolution()Update the elite solution. -
getResult
Description copied from interface:Algorithm
Returns the current best-known result.- Specified by:
getResult
in interfaceAlgorithm
- Overrides:
getResult
in classSingleObjectiveEvolutionaryAlgorithm
- Returns:
- the current best-known result
-
setVariation
Description copied from class:AbstractEvolutionaryAlgorithm
Replaces the variation operator to be used by this algorithm.- Overrides:
setVariation
in classAbstractEvolutionaryAlgorithm
- Parameters:
variation
- the variation operator
-
setComparator
Description copied from class:SingleObjectiveEvolutionaryAlgorithm
Sets the aggregate objective comparator that scalarizes multiple objectives into a single fitness value.- Overrides:
setComparator
in classSingleObjectiveEvolutionaryAlgorithm
- Parameters:
comparator
- the aggregate objective comparator
-
loadState
Description copied from interface:Stateful
Loads the state of this object from the stream. The order for reading objects from the stream must match the order they are written to the stream inStateful.saveState(ObjectOutputStream)
.- Specified by:
loadState
in interfaceStateful
- Overrides:
loadState
in classAbstractEvolutionaryAlgorithm
- Parameters:
stream
- the stream- Throws:
IOException
- if an I/O error occurredClassNotFoundException
- if the stream referenced a class that is not defined
-