JGAP

org.jgap
Class Population

java.lang.Object
  extended by org.jgap.Population
All Implemented Interfaces:
java.io.Serializable

public class Population
extends java.lang.Object
implements java.io.Serializable

List of chromosomes held in the Genotype (or possibly later in the Configuration object).

Since:
2.0
See Also:
Serialized Form

Constructor Summary
Population()
           
Population(Configuration a_config)
           
Population(Configuration a_config, IChromosome[] a_chromosomes)
           
Population(Configuration a_config, int a_size)
           
 
Method Summary
 void addChromosome(IChromosome a_toAdd)
          Adds a Chromosome to this Population.
 void addChromosomes(Population a_population)
          Adds all the Chromosomes in the given Population.
 int compareTo(java.lang.Object a_pop)
          This method is not producing symmetric results as -1 is more often returned than 1 (see description of return value).
 boolean contains(IChromosome a_chromosome)
          Determines whether the given chromosome is contained within the population.
 IChromosome determineFittestChromosome()
          Determines the fittest Chromosome in the population (the one with the highest fitness value) and memorizes it.
 IChromosome determineFittestChromosome(int a_startIndex, int a_endIndex)
          Determines the fittest Chromosome in the population (the one with the highest fitness value) within the given indices and memorizes it.
 java.util.List determineFittestChromosomes(int a_numberOfChromosomes)
          Sorts the Chromosome list and returns the fittest n Chromosomes in the population.
 boolean equals(java.lang.Object a_pop)
          The equals-method.
 IChromosome getChromosome(int a_index)
          Returns a Chromosome at given index in the Population.
 java.util.List getChromosomes()
           
 Configuration getConfiguration()
           
 java.util.List getGenome(boolean a_resolveCompositeGenes)
          Returns the genotype of the population, i.e. the list of genes in the population.
 boolean isChanged()
           
 boolean isSorted()
           
 java.util.Iterator iterator()
           
protected  void setChanged(boolean a_changed)
          Mark that for the population the fittest chromosome may have changed.
 void setChromosome(int a_index, IChromosome a_chromosome)
          Sets in the given Chromosome on the given index in the list of chromosomes.
 void setChromosomes(java.util.List a_chromosomes)
          Replaces all chromosomes in the population with the give list of chromosomes.
protected  void setSorted(boolean a_sorted)
          Mark the population as sorted.
 int size()
           
protected  void sort(java.util.Comparator a_comparator)
          Sorts the chromosomes within the population utilzing the given comparator.
 void sortByFitness()
          Sorts the chromosomes within the population according to their fitness value using ChromosomFitnessComparator.
 IChromosome[] toChromosomes()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Population

public Population(Configuration a_config)
           throws InvalidConfigurationException
Throws:
InvalidConfigurationException

Population

public Population(Configuration a_config,
                  IChromosome[] a_chromosomes)
           throws InvalidConfigurationException
Throws:
InvalidConfigurationException

Population

public Population(Configuration a_config,
                  int a_size)
           throws InvalidConfigurationException
Throws:
InvalidConfigurationException

Population

public Population()
           throws InvalidConfigurationException
Throws:
InvalidConfigurationException
Method Detail

getConfiguration

public Configuration getConfiguration()

addChromosome

public void addChromosome(IChromosome a_toAdd)
Adds a Chromosome to this Population. Does nothing when given null.

Parameters:
a_toAdd - the Chromosome to add
Since:
2.0

addChromosomes

public void addChromosomes(Population a_population)
Adds all the Chromosomes in the given Population. Does nothing on null or an empty Population.

Parameters:
a_population - the Population to add
Since:
2.0

setChromosomes

public void setChromosomes(java.util.List a_chromosomes)
Replaces all chromosomes in the population with the give list of chromosomes.

Parameters:
a_chromosomes - the chromosomes to make the population up from

setChromosome

public void setChromosome(int a_index,
                          IChromosome a_chromosome)
Sets in the given Chromosome on the given index in the list of chromosomes. If the given index is exceeding the list by one, the chromosome is appended.

Parameters:
a_index - the index to set the Chromosome in
a_chromosome - the Chromosome to be set
Since:
2.0

getChromosomes

public java.util.List getChromosomes()
Returns:
the list of Chromosome's in the Population. Don't modify the retrieved list by using clear(), remove(int) etc. If you do so, you need to call setChanged(true)
Since:
2.0

getChromosome

public IChromosome getChromosome(int a_index)
Returns a Chromosome at given index in the Population.

Parameters:
a_index - the index of the Chromosome to be returned
Returns:
Chromosome at given index in the Population
Since:
2.0

size

public int size()
Returns:
number of Chromosome's in the Population
Since:
2.0

iterator

public java.util.Iterator iterator()
Returns:
Iterator for the Chromosome list in the Population. Please be aware that using remove() forces you to call setChanged(true)
Since:
2.0

toChromosomes

public IChromosome[] toChromosomes()
Returns:
the Population converted into a list of Chromosome's
Since:
2.0

determineFittestChromosome

public IChromosome determineFittestChromosome()
Determines the fittest Chromosome in the population (the one with the highest fitness value) and memorizes it. This is an optimized version compared to calling determineFittesChromosomes(1).

Returns:
the fittest Chromosome of the population
Since:
2.0

determineFittestChromosome

public IChromosome determineFittestChromosome(int a_startIndex,
                                              int a_endIndex)
Determines the fittest Chromosome in the population (the one with the highest fitness value) within the given indices and memorizes it. This is an optimized version compared to calling determineFittesChromosomes(1).

Parameters:
a_startIndex - index to begin the evaluation with
a_endIndex - index to end the evaluation with
Returns:
the fittest Chromosome of the population within the given indices
Since:
3.0

setChanged

protected void setChanged(boolean a_changed)
Mark that for the population the fittest chromosome may have changed.

Parameters:
a_changed - true: population's fittest chromosome may have changed, false: fittest chromosome evaluated earlier is still valid
Since:
2.2

isChanged

public boolean isChanged()
Returns:
true: population's chromosomes (maybe) were changed, false: not changed for sure
Since:
2.6

setSorted

protected void setSorted(boolean a_sorted)
Mark the population as sorted.

Parameters:
a_sorted - true: mark population as sorted
Since:
2.6

contains

public boolean contains(IChromosome a_chromosome)
Determines whether the given chromosome is contained within the population.

Parameters:
a_chromosome - the chromosome to check
Returns:
true: chromosome contained within population
Since:
2.1

determineFittestChromosomes

public java.util.List determineFittestChromosomes(int a_numberOfChromosomes)
Sorts the Chromosome list and returns the fittest n Chromosomes in the population.

Parameters:
a_numberOfChromosomes - number of top performer chromosomes to be returned
Returns:
list of the fittest n Chromosomes of the population, or the fittest x Chromosomes with x = number of chromosomes in case n > x.
Since:
2.4

sortByFitness

public void sortByFitness()
Sorts the chromosomes within the population according to their fitness value using ChromosomFitnessComparator.

Since:
2.6

sort

protected void sort(java.util.Comparator a_comparator)
Sorts the chromosomes within the population utilzing the given comparator.

Parameters:
a_comparator - the comparator to utilize for sorting
Since:
2.6

getGenome

public java.util.List getGenome(boolean a_resolveCompositeGenes)
Returns the genotype of the population, i.e. the list of genes in the population.

Parameters:
a_resolveCompositeGenes - true: split encountered CompositeGenes into their single (atomic) genes
Returns:
genotype of the population
Since:
2.3

isSorted

public boolean isSorted()

equals

public boolean equals(java.lang.Object a_pop)
The equals-method.

Overrides:
equals in class java.lang.Object
Parameters:
a_pop - the population instance to compare with
Returns:
true: given object equal to comparing one
Since:
2.6

compareTo

public int compareTo(java.lang.Object a_pop)
This method is not producing symmetric results as -1 is more often returned than 1 (see description of return value).

Parameters:
a_pop - the other population to compare
Returns:
1: a_pop is null or having fewer chromosomes or equal number of chromosomes but at least one not contained. 0: both populations containing exactly the same chromosomes. -1: this population contains fewer chromosomes than a_pop
Since:
2.6

JGAP