artoflife pre0.1.0-dev

org.artoflife.gp
Class Individual

java.lang.Object
  |
  +--org.artoflife.gp.Individual
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable
Direct Known Subclasses:
MutableFitnessIndividual

public abstract class Individual
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

An Individual has a genotype containing a number of Chromosomes, a Fitness used during selection from a Population and a Phenotype resulting from expression of the genotype.

It can mutate via mutate(float) and can breed with another Individual via breedWith(Individual) to produce a child containing chromosomes that have undergone Chromosome.crossover(org.artoflife.gp.Chromosome). Individuals can also be cloned to produce a child with an exact copy of the parent's genome (see clone()).

The Chromosomes are indexed by their id so that crossover can take place between compatible Chromosomes.

An Individual's Phenotype is manipulated by Chromosomes during the expressGenome cycle. After expression, the Individual can calculate its Fitness on the basis of the its phenotype.

Author:
Steve Meyfroidt
See Also:
Fitness, Chromosome, Population, Phenotype, Serialized Form

Constructor Summary
Individual(Phenotype phenotype, Chromosome chromosome)
          Create with a single Chromosome, express the genotype and as a result create the initial Fitness.
Individual(Phenotype phenotype, java.util.Collection chromosomes)
          Create with a set of Chromosomes, express the genotype and as a result create the initial Fitness.
 
Method Summary
protected  void addChromsome(Chromosome chromosome)
           
 Individual breedWith(Individual parent2)
          Breed with another Individual by calling Chromosome.crossover(Chromosome) on all same-type Chromosomes in both parents.
 java.lang.Object clone()
          Override this to deep clone members of subclasses, eg the fitness if held as a field.
protected abstract  void expressGenome()
          Express this Individual's genotype as its phenotype.
 java.lang.String genotypeAsString()
          For debug.
protected  Chromosome getChromosome(java.lang.String id)
          Find a Chromosome in the Individual's genotype.
protected  java.util.Map getChromosomes()
           
abstract  Fitness getFitness()
          Override to describe how fit this Individual is.
 int getGenomeSize()
          May be used in some selection strategies to select small fit Individuals.
 Phenotype getPhenotype()
           
 void mutate(float probability)
          Mutate this Individual's genome by mutating every Chromosome.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Individual

public Individual(Phenotype phenotype,
                  java.util.Collection chromosomes)
Create with a set of Chromosomes, express the genotype and as a result create the initial Fitness.

Parameters:
phenotype - this Individual's Phenotype used during expressGenome()
chromosomes - Collection of Chromosomes making up this Individual's genotype.

Individual

public Individual(Phenotype phenotype,
                  Chromosome chromosome)
Create with a single Chromosome, express the genotype and as a result create the initial Fitness.

Parameters:
phenotype - this Individual's Phenotype used during expressGenome()
chromosome - single Chromosome this Individual has.
Method Detail

getChromosomes

protected java.util.Map getChromosomes()
Returns:
the Map of Integer ID against Chromosome making up this Individual's genotype. Treat as immutable, or call expressGenome() after making changes.

getChromosome

protected Chromosome getChromosome(java.lang.String id)
Find a Chromosome in the Individual's genotype. * @param id find a Chromsome with this id * @return Chromosome the Chromosome with the passed id from the Individual's genotype


getPhenotype

public Phenotype getPhenotype()
Returns:
the phenotype of this Individual. Null until expressGenome() has been called.

addChromsome

protected void addChromsome(Chromosome chromosome)
Parameters:
chromosome - to add to the genotype, replacing any of the same id already in the genome. This does not call expressGenome().

getGenomeSize

public int getGenomeSize()
May be used in some selection strategies to select small fit Individuals.

Returns:
a measure of the size of this Individual's genotype

mutate

public void mutate(float probability)
Mutate this Individual's genome by mutating every Chromosome.

Parameters:
probability - of mutation, see Chromosome.mutate(float)
See Also:
Chromosome.mutate(float)

breedWith

public Individual breedWith(Individual parent2)
                     throws IncompatibleGenotypeException
Breed with another Individual by calling Chromosome.crossover(Chromosome) on all same-type Chromosomes in both parents.

Parameters:
parent2 - Individual to breed with
Returns:
child Individual resulting from crossover between the parent genotypes
Throws:
IncompatibleGenotypeException - if the individuals have incompatible genotypes
See Also:
Chromosome.crossover(Chromosome)
To do:
make this more flexible with multiple chromosomes?

getFitness

public abstract Fitness getFitness()
Override to describe how fit this Individual is. For some applications (equation solvers) it might be sensible to cache the Fitness in expressGenome() since the fitness is a direct result of the genome and doesn't change. during the lifetime. For other others the Fitness may change during lifetime.


expressGenome

protected abstract void expressGenome()
Express this Individual's genotype as its phenotype. Called whenever the genome changes to allow the internal state to be synchronised with the current genome.

Should be called from any methods in an Individual that mutates the genotype.

Override appropriate to the system being modelled.

Can this be replaced with a generic implementation or does it have to be abstract so that implementations can express Chromosomes in a certain order to do certain things?


clone

public java.lang.Object clone()
Override this to deep clone members of subclasses, eg the fitness if held as a field.

Overrides:
clone in class java.lang.Object
Returns:
an Individual that is an independent deep clone.

genotypeAsString

public java.lang.String genotypeAsString()
For debug.


artoflife pre0.1.0-dev

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