Package org.apache.commons.math.genetics
Class ListPopulation
- java.lang.Object
-
- org.apache.commons.math.genetics.ListPopulation
-
- All Implemented Interfaces:
java.lang.Iterable<Chromosome>
,Population
- Direct Known Subclasses:
ElitisticListPopulation
public abstract class ListPopulation extends java.lang.Object implements Population
Population of chromosomes represented by aList
.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description ListPopulation(int populationLimit)
Creates a new ListPopulation instance and initializes its inner chromosome list.ListPopulation(java.util.List<Chromosome> chromosomes, int populationLimit)
Creates a new ListPopulation instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChromosome(Chromosome chromosome)
Add the given chromosome to the population.java.util.List<Chromosome>
getChromosomes()
Access the list of chromosomes.Chromosome
getFittestChromosome()
Access the fittest chromosome in this population.int
getPopulationLimit()
Access the maximum population size.int
getPopulationSize()
Access the current population size.java.util.Iterator<Chromosome>
iterator()
Chromosome list iteratorvoid
setChromosomes(java.util.List<Chromosome> chromosomes)
Sets the list of chromosomes.void
setPopulationLimit(int populationLimit)
Sets the maximal population size.java.lang.String
toString()
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.math.genetics.Population
nextGeneration
-
-
-
-
Constructor Detail
-
ListPopulation
public ListPopulation(java.util.List<Chromosome> chromosomes, int populationLimit)
Creates a new ListPopulation instance.- Parameters:
chromosomes
- list of chromosomes in the populationpopulationLimit
- maximal size of the population
-
ListPopulation
public ListPopulation(int populationLimit)
Creates a new ListPopulation instance and initializes its inner chromosome list.- Parameters:
populationLimit
- maximal size of the population
-
-
Method Detail
-
setChromosomes
public void setChromosomes(java.util.List<Chromosome> chromosomes)
Sets the list of chromosomes.- Parameters:
chromosomes
- the list of chromosomes
-
getChromosomes
public java.util.List<Chromosome> getChromosomes()
Access the list of chromosomes.- Returns:
- the list of chromosomes
-
addChromosome
public void addChromosome(Chromosome chromosome)
Add the given chromosome to the population.- Specified by:
addChromosome
in interfacePopulation
- Parameters:
chromosome
- the chromosome to add.
-
getFittestChromosome
public 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)
Sets the maximal population size.- Parameters:
populationLimit
- maximal population size.
-
getPopulationSize
public int getPopulationSize()
Access the current population size.- Specified by:
getPopulationSize
in interfacePopulation
- Returns:
- the current population size.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
iterator
public java.util.Iterator<Chromosome> iterator()
Chromosome list iterator- Specified by:
iterator
in interfacejava.lang.Iterable<Chromosome>
- Returns:
- chromosome iterator
-
-