## org.apache.commons.math3.genetics
Class ListPopulation

    java.lang.Object
      org.apache.commons.math3.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 a `List`.

Since:
  2.0
Version:
  $Id: ListPopulation.java 1422195 2012-12-15 06:45:18Z psteitz $

Field Summary
`private java.util.List<Chromosome>` `chromosomes` List of chromosomes
`private int` `populationLimit` maximal size of the population

Constructor Summary
`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
`void` `addChromosome(Chromosome chromosome)` Add the given chromosome to the population.
`void` `addChromosomes(java.util.Collection<Chromosome> chromosomeColl)` Add a `Collection` of chromosomes to this `Population`.
`protected java.util.List<Chromosome>` `getChromosomeList()` Access the list of chromosomes.
`java.util.List<Chromosome>` `getChromosomes()` Returns an unmodifiable list of the chromosomes in this population.
`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()` Returns an iterator over the unmodifiable list of chromosomes.
`void` `setChromosomes(java.util.List<Chromosome> chromosomes)` Deprecated. use `addChromosomes(Collection)` instead
`void` `setPopulationLimit(int populationLimit)` Sets the maximal population size.
`java.lang.String` `toString()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.apache.commons.math3.genetics.Population
`nextGeneration`

Field Detail

### chromosomes

    private java.util.List<Chromosome> chromosomes

  List of chromosomes

### populationLimit

    private int populationLimit

  maximal size of the population

Constructor Detail

### ListPopulation

    public ListPopulation(int populationLimit)
                   throws NotPositiveException

  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(java.util.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 population
    `populationLimit` - maximal size of the population
  Throws:
    `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

### setChromosomes

    @Deprecated
    public void setChromosomes(java.util.List<Chromosome> chromosomes)
                        throws NullArgumentException,
                               NumberIsTooLargeException

  Deprecated. use `addChromosomes(Collection)` instead

  Sets the list of chromosomes.

  Note: this method removed 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 is `null`
    `NumberIsTooLargeException` - if the list of chromosomes exceeds the population limit

### addChromosomes

    public void addChromosomes(java.util.Collection<Chromosome> chromosomeColl)
                        throws NumberIsTooLargeException

  Add a `Collection` of chromosomes to this `Population`.

  Parameters:
    `chromosomeColl` - a `Collection` of chromosomes
  Throws:
    `NumberIsTooLargeException` - if the population would exceed the population limit when adding this chromosome
  Since:
    3.1

### getChromosomes

    public java.util.List<Chromosome> getChromosomes()

  Returns an unmodifiable list of the chromosomes in this population.

  Returns:
    the unmodifiable list of chromosomes

### getChromosomeList

    protected java.util.List<Chromosome> getChromosomeList()

  Access the list of chromosomes.

  Returns:
    the list of chromosomes
  Since:
    3.1

### addChromosome

    public void addChromosome(Chromosome chromosome)
                       throws NumberIsTooLargeException

  Add the given chromosome to the population.

  Specified by:
    `addChromosome` in interface `Population`
  Parameters:
    `chromosome` - the chromosome to add.
  Throws:
    `NumberIsTooLargeException` - if the population would exceed the `populationLimit` after adding this chromosome

### getFittestChromosome

    public Chromosome getFittestChromosome()

  Access the fittest chromosome in this population.

  Specified by:
    `getFittestChromosome` in interface `Population`
  Returns:
    the fittest chromosome.

### getPopulationLimit

    public int getPopulationLimit()

  Access the maximum population size.

  Specified by:
    `getPopulationLimit` in interface `Population`
  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 interface `Population`
  Returns:
    the current population size.

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

### iterator

    public java.util.Iterator<Chromosome> iterator()

  Returns an iterator over the unmodifiable list of chromosomes.

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

  Specified by:
    `iterator` in interface `java.lang.Iterable<Chromosome>`
  Returns:
    chromosome iterator

Copyright (c) 2003-2013 Apache Software Foundation