|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.artoflife.gp.Population
A Population contains a number of Individual
s, has an ideal size that
will be maintained during a breeding cycle, can add and remove Individuals
and populates new generations using Reproducer
s. An interested
listener can register to receive notification of changes to the population.
A Population initialises itself with new "Adams and Eves" in the first
generation (see newIndividual()
), and then creates new generations
(see breed()
) using a Selector
to choose Individuals and a
random choice from its set of Reproducer
s to create the child
Individuals (see breedNewIndividual(Selector)
).
Instances fire PopulationEvents
to PopulationListeners
to
notify of changes including addition and deletion of Individuals: this enables the
creation of decoupled views to watch the population as it develops.
Population implementations need to be thread-safe unfortunately.
Field Summary | |
protected java.util.Set |
individuals
|
Constructor Summary | |
Population(java.util.SortedMap reproducers)
|
Method Summary | |
void |
addIndividual(Individual newIndividual)
Add a new Individual to the Population, culling one if necessary to maintain the ideal population size. |
protected void |
addNewIndividuals(int number)
Make a number of new Individuals and add them to this Population. |
void |
addPopulationListener(PopulationListener listener)
|
protected abstract void |
breed()
Override to implement breeding policy, returning the population size to the getIdealPopulationSize() . |
Individual |
breedNewIndividual(Selector selector)
Using a passed Selector, apply configured breeding strategies ( Reproducer s) to breed a new Individual from parents
selected from the population, or possibly a brand new Individual if
reproducer probabilities don't end at 1.0. |
protected abstract void |
cullOneWeakest()
|
protected abstract void |
cullWeakest()
Override to implement a cull policy, for example a fixed number culled every generation or just the Individuals weaker than some threshold. |
void |
firePopulationEvent(PopulationEvent event)
|
abstract int |
getIdealPopulationSize()
|
java.util.Set |
getIndividuals()
|
protected java.util.SortedMap |
getReproducers()
Provides a SortedMap of Reproducers with their probabilities (Doubles between 0.0 and 1.0) so that breedNewIndividual(Selector)
can choose one to do a reproduction. |
void |
newGeneration()
Breed the population through one generation, returning its size back to getIdealPopulationSize() : first cull the weaklings and then
breed new children to make up the full population size. |
abstract Individual |
newIndividual()
Override to create a new Individual. |
void |
removeIndividual(Individual individual)
Remove an Individual from the Population (without replacing with a newly bred one), and notify listeners of the change. |
void |
removePopulationListener(PopulationListener listener)
|
protected abstract void |
setIdealPopulationSize(int idealSize)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.util.Set individuals
Constructor Detail |
public Population(java.util.SortedMap reproducers)
reproducers
- to use when breeding new generationsMethod Detail |
public java.util.Set getIndividuals()
protected abstract void setIdealPopulationSize(int idealSize)
idealSize
- the number of Individuals that the population aims to
maintain in newGeneration()
.public abstract int getIdealPopulationSize()
newGeneration()
.protected void addNewIndividuals(int number)
number
- of new Individuals to add to the populationpublic abstract Individual newIndividual()
public void newGeneration()
getIdealPopulationSize()
: first cull the weaklings and then
breed new children to make up the full population size. If the population
contains no Individuals then initialise it by creating an initial
population using addNewIndividuals(int)
.
protected abstract void cullWeakest()
breed()
on each new generation and should ideally
result in a population size less than or equal to getIdealPopulationSize()
.
protected abstract void cullOneWeakest()
protected abstract void breed()
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 cullWeakest()
on each new generation.
#getPopulationSize()
,
getReproducers()
public Individual breedNewIndividual(Selector selector) throws IncompatibleGenotypeException
Reproducer
s) to breed a new Individual
from parents
selected from the population, or possibly a brand new Individual if
reproducer probabilities don't end at 1.0.
selector
- to use for selection of parents of the breeding
IncompatibleGenotypeException
- when breeding between
individuals with incompatible genotypespublic void removeIndividual(Individual individual)
individual
- the Individual to remove (does nothing
if the Individual can't be found in the Population)public void addIndividual(Individual newIndividual) throws IncompatibleGenotypeException
newIndividual
- the Individual to be added into the Population, does
nothing if the individual is already in the population
IncompatibleGenotypeException
- if the individual to be added has a genotype
that is incompatible with the rest of this populationprotected java.util.SortedMap getReproducers()
breedNewIndividual(Selector)
can choose one to do a reproduction.
Configuration.getInstancesProbabilities(String)
public void addPopulationListener(PopulationListener listener)
public void removePopulationListener(PopulationListener listener)
public void firePopulationEvent(PopulationEvent event)
|
artoflife pre0.1.0-dev | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |