Class ListPopulation
java.lang.Object
org.apache.commons.math3.genetics.ListPopulation
- All Implemented Interfaces:
Iterable<Chromosome>
,Population
- Direct Known Subclasses:
ElitisticListPopulation
Population of chromosomes represented by a
List
.- Since:
- 2.0
-
Constructor Summary
ConstructorsConstructorDescriptionListPopulation
(int populationLimit) Creates a new ListPopulation instance and initializes its inner chromosome list.ListPopulation
(List<Chromosome> chromosomes, int populationLimit) Creates a new ListPopulation instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChromosome
(Chromosome chromosome) Add the given chromosome to the population.void
addChromosomes
(Collection<Chromosome> chromosomeColl) Add aCollection
of chromosomes to thisPopulation
.protected List
<Chromosome> Access the list of chromosomes.Returns an unmodifiable list of the chromosomes in this population.Access the fittest chromosome in this population.int
Access the maximum population size.int
Access the current population size.iterator()
Returns an iterator over the unmodifiable list of chromosomes.void
setChromosomes
(List<Chromosome> chromosomes) Deprecated.void
setPopulationLimit
(int populationLimit) Sets the maximal population size.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
Methods inherited from interface org.apache.commons.math3.genetics.Population
nextGeneration
-
Constructor Details
-
ListPopulation
Creates a new ListPopulation instance and initializes its inner chromosome list.- Parameters:
populationLimit
- maximal size of the population- Throws:
NotPositiveException
- if the population limit is not a positive number (< 1)
-
ListPopulation
public ListPopulation(List<Chromosome> chromosomes, int populationLimit) throws NullArgumentException, NotPositiveException, NumberIsTooLargeException Creates a new ListPopulation instance.Note: the chromosomes of the specified list are added to the population.
- Parameters:
chromosomes
- list of chromosomes to be added to the populationpopulationLimit
- maximal size of the population- Throws:
NullArgumentException
- if the list of chromosomes isnull
NotPositiveException
- if the population limit is not a positive number (< 1)NumberIsTooLargeException
- if the list of chromosomes exceeds the population limit
-
-
Method Details
-
setChromosomes
@Deprecated public void setChromosomes(List<Chromosome> chromosomes) throws NullArgumentException, NumberIsTooLargeException Deprecated.useaddChromosomes(Collection)
insteadSets the list of chromosomes.Note: this method removes all existing chromosomes in the population and adds all chromosomes of the specified list to the population.
- Parameters:
chromosomes
- the list of chromosomes- Throws:
NullArgumentException
- if the list of chromosomes isnull
NumberIsTooLargeException
- if the list of chromosomes exceeds the population limit
-
addChromosomes
Add aCollection
of chromosomes to thisPopulation
.- Parameters:
chromosomeColl
- aCollection
of chromosomes- Throws:
NumberIsTooLargeException
- if the population would exceed the population limit when adding this chromosome- Since:
- 3.1
-
getChromosomes
Returns an unmodifiable list of the chromosomes in this population.- Returns:
- the unmodifiable list of chromosomes
-
getChromosomeList
Access the list of chromosomes.- Returns:
- the list of chromosomes
- Since:
- 3.1
-
addChromosome
Add the given chromosome to the population.- Specified by:
addChromosome
in interfacePopulation
- Parameters:
chromosome
- the chromosome to add.- Throws:
NumberIsTooLargeException
- if the population would exceed thepopulationLimit
after adding this chromosome
-
getFittestChromosome
Access the fittest chromosome in this population.- Specified by:
getFittestChromosome
in interfacePopulation
- Returns:
- the fittest chromosome.
-
getPopulationLimit
public int getPopulationLimit()Access the maximum population size.- Specified by:
getPopulationLimit
in interfacePopulation
- Returns:
- the maximum population size.
-
setPopulationLimit
public void setPopulationLimit(int populationLimit) throws NotPositiveException, NumberIsTooSmallException Sets the maximal population size.- Parameters:
populationLimit
- maximal population size.- Throws:
NotPositiveException
- if the population limit is not a positive number (< 1)NumberIsTooSmallException
- if the new population size is smaller than the current number of chromosomes in the population
-
getPopulationSize
public int getPopulationSize()Access the current population size.- Specified by:
getPopulationSize
in interfacePopulation
- Returns:
- the current population size.
-
toString
-
iterator
Returns an iterator over the unmodifiable list of chromosomes.Any call to
Iterator.remove()
will result in aUnsupportedOperationException
.- Specified by:
iterator
in interfaceIterable<Chromosome>
- Returns:
- chromosome iterator
-
addChromosomes(Collection)
instead