Orbital library

orbital.algorithm.evolutionary
Class Population

java.lang.Object
  extended by orbital.algorithm.evolutionary.Population
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ParallelEvaluationPopulation, PopulationImpl

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

This class represents a population of genomes as a data structure. Some of these Genomes will reproduce with Genome.recombine to generate the members of the next generation.

A population provides the following operators and functions:

Author:
André Platzer
See Also:
Serialized Form
Invariants:
sub classes must support nullary constructor (for cloning)
Structure:
extend List sorted on descending Genome.getFitness(), aggregate members:List

Constructor Summary
protected Population()
          Create an empty population.
 
Method Summary
 boolean add(java.lang.Object o)
          Append a genome without replacing which will increase the size.
 java.lang.Object clone()
          Returns a deep copy of this population.
static Population create(Genome prototype, int size)
          Generate (create) a new random population of genomes.
static Population create(Population population, Genome prototype, int size)
          Generate (create) a new random population of genomes.
 boolean equals(java.lang.Object o)
          Checks for equality.
 void evaluate(boolean redo)
          Evaluates the fitness of the Genomes, if necessary.
 Genome get(int i)
          Gets the i-th member-Genome.
 Genome get(int i, boolean best)
          Get the i-th member in the order specified.
 double[] getFitnessArray()
          Returns an array with the fitness values of all genomes.
 int getGeneration()
          Get the current generation count.
 java.util.List getMembers()
           
 double getOverallDistance()
          Calculate an overall difference of all genomes in the population with several difference comparisons.
 int hashCode()
           
 java.util.Iterator iterator()
           
 java.util.ListIterator listIterator()
           
 java.util.ListIterator listIterator(int index)
           
 java.lang.Object remove(int index)
           
 boolean remove(java.lang.Object o)
           
protected  void setGeneration(int newGeneration)
           
 int size()
          Get the size of population i.e.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Population

protected Population()
Create an empty population.

Method Detail

clone

public java.lang.Object clone()
Returns a deep copy of this population.

Overrides:
clone in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Checks for equality.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getGeneration

public int getGeneration()
Get the current generation count.


setGeneration

protected void setGeneration(int newGeneration)

get

public Genome get(int i)
Gets the i-th member-Genome.


get

public Genome get(int i,
                  boolean best)
Get the i-th member in the order specified.

Parameters:
best - whether to get the i-th best, or the i-th worst.

getOverallDistance

public double getOverallDistance()
Calculate an overall difference of all genomes in the population with several difference comparisons.


getFitnessArray

public double[] getFitnessArray()
Returns an array with the fitness values of all genomes. For purpose of statistics.


size

public int size()
Get the size of population i.e. the number of member genomes in it.


add

public boolean add(java.lang.Object o)
Append a genome without replacing which will increase the size.

See Also:
merge(Genome)

remove

public boolean remove(java.lang.Object o)

remove

public java.lang.Object remove(int index)

iterator

public java.util.Iterator iterator()

listIterator

public java.util.ListIterator listIterator()

listIterator

public java.util.ListIterator listIterator(int index)

getMembers

public java.util.List getMembers()

evaluate

public void evaluate(boolean redo)
Evaluates the fitness of the Genomes, if necessary.

Default implementation will call evaluate for each member Genome.

Parameters:
redo - force whole evaluation again, even for cached fitness values. Should usually be false for efficiency reasons.

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object

create

public static Population create(Population population,
                                Genome prototype,
                                int size)
Generate (create) a new random population of genomes.

Note that the prototype genome should not contain genes that are immune to mutation since that is an essential part of creating an initial random population without problem specific means.

Also note that a mixed random and problem specific initial population might get better results. So consider merging them.

Parameters:
population - the population to fill with Genomes.
size - the initial size of the new population. i.e. the initial number of Genomes.
prototype - the genome prototype to clone and mutate to create the population. The prototype must have the right structure to serve as a problem specific solution, but does not necessarily need to have meaningful values.
Returns:
the population filled with random genomes according to the prototype. Note: this population will not yet have been evaluated.
See Also:
Facade Method, Genome.mutate(double), Genome.inverse()

create

public static Population create(Genome prototype,
                                int size)
Generate (create) a new random population of genomes.

Note that the prototype genome should not contain genes that are immune to mutation since that is an essential part of creating an initial random population without problem specific means.

Also note that a mixed random and problem specific initial population might get better results. So consider merging them.

Parameters:
size - the initial size of the new population. i.e. the initial number of Genomes.
prototype - the genome prototype to clone and mutate to create the population The prototype must have the right structure to serve as a problem specific solution, but does not necessarily need to have meaningful values.
Returns:
a new random population with genomes according to the prototype.
See Also:
Facade Method, Genome.mutate(double), Genome.inverse()

Orbital library
1.3.0: 11 Apr 2009

Copyright © 1996-2009 André Platzer
All Rights Reserved.