Class ElitisticListPopulation
- java.lang.Object
-
- org.apache.commons.math4.legacy.genetics.ListPopulation
-
- org.apache.commons.math4.legacy.genetics.ElitisticListPopulation
-
- All Implemented Interfaces:
Iterable<Chromosome>,Population
public class ElitisticListPopulation extends ListPopulation
Population of chromosomes which uses elitism (certain percentage of the best chromosomes is directly copied to the next generation).- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description ElitisticListPopulation(int populationLimit, double elitismRate)Creates a newElitisticListPopulationinstance and initializes its inner chromosome list.ElitisticListPopulation(List<Chromosome> chromosomes, int populationLimit, double elitismRate)Creates a newElitisticListPopulationinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublegetElitismRate()Access the elitism rate.PopulationnextGeneration()Start the population for the next generation.voidsetElitismRate(double elitismRate)Sets the elitism rate, i.e.-
Methods inherited from class org.apache.commons.math4.legacy.genetics.ListPopulation
addChromosome, addChromosomes, getChromosomeList, getChromosomes, getFittestChromosome, getPopulationLimit, getPopulationSize, iterator, setPopulationLimit, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
ElitisticListPopulation
public ElitisticListPopulation(List<Chromosome> chromosomes, int populationLimit, double elitismRate) throws NullArgumentException, NotPositiveException, NumberIsTooLargeException, OutOfRangeException
Creates a newElitisticListPopulationinstance.- Parameters:
chromosomes- list of chromosomes in the populationpopulationLimit- maximal size of the populationelitismRate- how many best chromosomes will be directly transferred to the next generation [in %]- Throws:
NullArgumentException- if the list of chromosomes isnullNotPositiveException- if the population limit is not a positive number (< 1)NumberIsTooLargeException- if the list of chromosomes exceeds the population limitOutOfRangeException- if the elitism rate is outside the [0, 1] range
-
ElitisticListPopulation
public ElitisticListPopulation(int populationLimit, double elitismRate) throws NotPositiveException, OutOfRangeException
Creates a newElitisticListPopulationinstance and initializes its inner chromosome list.- Parameters:
populationLimit- maximal size of the populationelitismRate- how many best chromosomes will be directly transferred to the next generation [in %]- Throws:
NotPositiveException- if the population limit is not a positive number (< 1)OutOfRangeException- if the elitism rate is outside the [0, 1] range
-
-
Method Detail
-
nextGeneration
public Population nextGeneration()
Start the population for the next generation. Thepercents of the best chromosomes are directly copied to the next generation.elitismRate- Returns:
- the beginnings of the next generation.
-
setElitismRate
public void setElitismRate(double elitismRate) throws OutOfRangeException
Sets the elitism rate, i.e. how many best chromosomes will be directly transferred to the next generation [in %].- Parameters:
elitismRate- how many best chromosomes will be directly transferred to the next generation [in %]- Throws:
OutOfRangeException- if the elitism rate is outside the [0, 1] range
-
getElitismRate
public double getElitismRate()
Access the elitism rate.- Returns:
- the elitism rate
-
-