artoflife pre0.1.0-dev

org.artoflife.gp.population
Class GenerationalPopulation

java.lang.Object
  |
  +--org.artoflife.gp.Population
        |
        +--org.artoflife.gp.population.GenerationalPopulation
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
MinFitnessGenerationalPopulation, SelectorGenerationalPopulation

public abstract class GenerationalPopulation
extends Population

A Population that breeds new Individuals into the main population to replace dead ones.

A breeding cycle looks like:

  1. Cull some Individuals from the main population,
  2. Breed new offspring by selection among the survivors until the population is up to the right size.

The culling strategy is implemented in concrete subclasses, but this base class implements a breeding strategy based on selection using a Selector defined by makeSelector() which can be overridden.

Author:
Steve Meyfroidt
See Also:
Serialized Form

Field Summary
protected static java.util.Comparator FITNESS_COMPARATOR
          Shared instance.
protected  java.lang.Class individualClass
           
protected  int populationSize
           
protected  java.lang.Class selectorClass
           
 
Fields inherited from class org.artoflife.gp.Population
individuals
 
Constructor Summary
GenerationalPopulation(int populationSize, java.lang.Class individualClass, java.util.SortedMap reproducers)
           
 
Method Summary
protected  void breed()
          Override to implement breeding policy, returning the population size to the getIdealPopulationSize().
 int getIdealPopulationSize()
          Can be overriden.
protected  Selector makeSelector()
          Create a new Selector.
 Individual newIndividual()
          Create a new Individual.
 void setIdealPopulationSize(int idealSize)
           
 void setSelectorClass(java.lang.Class selectorClass)
           
 
Methods inherited from class org.artoflife.gp.Population
addIndividual, addNewIndividuals, addPopulationListener, breedNewIndividual, cullOneWeakest, cullWeakest, firePopulationEvent, getIndividuals, getReproducers, newGeneration, removeIndividual, removePopulationListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FITNESS_COMPARATOR

protected static final java.util.Comparator FITNESS_COMPARATOR
Shared instance.


selectorClass

protected java.lang.Class selectorClass

populationSize

protected int populationSize

individualClass

protected java.lang.Class individualClass
Constructor Detail

GenerationalPopulation

public GenerationalPopulation(int populationSize,
                              java.lang.Class individualClass,
                              java.util.SortedMap reproducers)
Parameters:
populationSize - how many Individuals in this fixed size population? Must be > 2
individualClass - Class of individuals to create as initial population. Must be non-null
reproducers - to use when breeding new generation. See Configuration.getInstancesProbabilities(String)
Method Detail

setSelectorClass

public void setSelectorClass(java.lang.Class selectorClass)

breed

protected void breed()
Description copied from class: Population
Override to implement breeding policy, returning the population size to the Population.getIdealPopulationSize(). For example you could fill a nursery by mating strongest Individuals in Population then move strongest from nursery into main population. This is called after Population.cullWeakest() on each new generation.

Specified by:
breed in class Population
See Also:
Population.breed()

makeSelector

protected Selector makeSelector()
Create a new Selector.

See Also:
setSelectorClass(Class)

getIdealPopulationSize

public int getIdealPopulationSize()
Can be overriden. Here returns a constant passed at construction.

Specified by:
getIdealPopulationSize in class Population
Returns:
the number of Individuals that the population aims to maintain in Population.newGeneration().

setIdealPopulationSize

public void setIdealPopulationSize(int idealSize)
Specified by:
setIdealPopulationSize in class Population
Parameters:
idealSize - the number of Individuals that the population aims to maintain in Population.newGeneration().

newIndividual

public Individual newIndividual()
Create a new Individual. Used to fill the Population upon construction. Default implementation here creates a new instance of the class passed on construction. Override for other behaviour.

Specified by:
newIndividual in class Population
Returns:
a newly bred Individual

artoflife pre0.1.0-dev

Copyright © 2002 the Art Of Life team. All Rights Reserved.