Top Description Fields Constructors Methods
org.apache.commons.math3.genetics

public abstract Class ListPopulation

extends Object
implements Population
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.genetics.Population, java.lang.Iterable
Known Direct Subclasses
org.apache.commons.math3.genetics.ElitisticListPopulation
Imports
java.util.ArrayList, .Collection, .Collections, .Iterator, .List, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.exception.NotPositiveException, .NullArgumentException, .NumberIsTooLargeException, .NumberIsTooSmallException

Population of chromosomes represented by a List.
Since
2.0

Field Summary

Modifier and TypeField and Description
private List<Chromosome>
chromosomes

List of chromosomes

private int
populationLimit

maximal size of the population

Constructor Summary

AccessConstructor and Description
public
ListPopulation(final int
maximal size of the population
populationLimit
)

Creates a new ListPopulation instance and initializes its inner chromosome list.

public
ListPopulation(final List<Chromosome>
list of chromosomes to be added to the population
chromosomes
,
final int
maximal size of the population
populationLimit
)

Creates a new ListPopulation instance.

Method Summary

Modifier and TypeMethod and Description
public void
addChromosome(final Chromosome
the chromosome to add.
chromosome
)

Implements org.apache.commons.math3.genetics.Population.addChromosome.

Add the given chromosome to the population.

public void
addChromosomes(final Collection<Chromosome>
a Collection of chromosomes
chromosomeColl
)

Add a Collection of chromosomes to this Population.

protected List<Chromosome>

Returns:

the list of chromosomes
getChromosomeList
()

Access the list of chromosomes.

public List<Chromosome>

Returns:

the unmodifiable list of chromosomes
getChromosomes
()

Returns an unmodifiable list of the chromosomes in this population.

public Chromosome

Returns:

the fittest chromosome.
getFittestChromosome
()

Implements org.apache.commons.math3.genetics.Population.getFittestChromosome.

Access the fittest chromosome in this population.

public int

Returns:

the maximum population size.
getPopulationLimit
()

Implements org.apache.commons.math3.genetics.Population.getPopulationLimit.

Access the maximum population size.

public int

Returns:

the current population size.
getPopulationSize
()

Implements org.apache.commons.math3.genetics.Population.getPopulationSize.

Access the current population size.

public Iterator<Chromosome>

Returns:

chromosome iterator
iterator
()

Implements java.lang.Iterable.iterator.

Returns an iterator over the unmodifiable list of chromosomes.

public void
setChromosomes(final List<Chromosome>
the list of chromosomes
chromosomes
)
Deprecated use addChromosomes(Collection) instead

Sets the list of chromosomes.

public void
setPopulationLimit(final int
maximal population size.
populationLimit
)

Sets the maximal population size.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

chromosomesback to summary
private List<Chromosome> chromosomes

List of chromosomes

populationLimitback to summary
private int populationLimit

maximal size of the population

Constructor Detail

ListPopulationback to summary
public ListPopulation(final int populationLimit) throws NotPositiveException

Creates a new ListPopulation instance and initializes its inner chromosome list.

Parameters
populationLimit:int

maximal size of the population

Exceptions
NotPositiveException:
if the population limit is not a positive number (< 1)
ListPopulationback to summary
public ListPopulation(final List<Chromosome> chromosomes, final 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<Chromosome>

list of chromosomes to be added to the population

populationLimit:int

maximal size of the population

Exceptions
NullArgumentException:
if the list of chromosomes is null
NotPositiveException:
if the population limit is not a positive number (< 1)
NumberIsTooLargeException:
if the list of chromosomes exceeds the population limit

Method Detail

addChromosomeback to summary
public void addChromosome(final Chromosome chromosome) throws NumberIsTooLargeException

Implements org.apache.commons.math3.genetics.Population.addChromosome.

Add the given chromosome to the population.

Parameters
chromosome:Chromosome

the chromosome to add.

Exceptions
NumberIsTooLargeException:
if the population would exceed the populationLimit after adding this chromosome
addChromosomesback to summary
public void addChromosomes(final Collection<Chromosome> chromosomeColl) throws NumberIsTooLargeException

Add a Collection of chromosomes to this Population.

Parameters
chromosomeColl:Collection<Chromosome>

a Collection of chromosomes

Exceptions
NumberIsTooLargeException:
if the population would exceed the population limit when adding this chromosome
Since
3.1
getChromosomeListback to summary
protected List<Chromosome> getChromosomeList()

Access the list of chromosomes.

Returns:List<Chromosome>

the list of chromosomes

Since
3.1
getChromosomesback to summary
public List<Chromosome> getChromosomes()

Returns an unmodifiable list of the chromosomes in this population.

Returns:List<Chromosome>

the unmodifiable list of chromosomes

getFittestChromosomeback to summary
public Chromosome getFittestChromosome()

Implements org.apache.commons.math3.genetics.Population.getFittestChromosome.

Access the fittest chromosome in this population.

Returns:Chromosome

the fittest chromosome.

getPopulationLimitback to summary
public int getPopulationLimit()

Implements org.apache.commons.math3.genetics.Population.getPopulationLimit.

Access the maximum population size.

Returns:int

the maximum population size.

getPopulationSizeback to summary
public int getPopulationSize()

Implements org.apache.commons.math3.genetics.Population.getPopulationSize.

Access the current population size.

Returns:int

the current population size.

iteratorback to summary
public Iterator<Chromosome> iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over the unmodifiable list of chromosomes.

Any call to Iterator#remove() will result in a UnsupportedOperationException.

Returns:Iterator<Chromosome>

chromosome iterator

setChromosomesback to summary
public void setChromosomes(final List<Chromosome> chromosomes) throws NullArgumentException, NumberIsTooLargeException

Deprecated

use addChromosomes(Collection) instead

Sets 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:List<Chromosome>

the list of chromosomes

Annotations
@Deprecated
Exceptions
NullArgumentException:
if the list of chromosomes is null
NumberIsTooLargeException:
if the list of chromosomes exceeds the population limit
setPopulationLimitback to summary
public void setPopulationLimit(final int populationLimit) throws NotPositiveException, NumberIsTooSmallException

Sets the maximal population size.

Parameters
populationLimit:int

maximal population size.

Exceptions
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
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override