artoflife pre0.1.0-dev

org.artoflife.gp.genome
Class GpTreeNode

java.lang.Object
  |
  +--org.artoflife.gp.genome.GpTreeNode
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable
Direct Known Subclasses:
BooleanGene, FloatGene, FunctionGene, VariableGene

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

A gene in a GpTreeChromosome that returns a certain type. Has an ordered list of parameter genes which are themselves GpTreeNodes that return a certain type. Any parameter may be null.

Author:
Steve Meyfroidt
See Also:
Serialized Form

Constructor Summary
GpTreeNode()
           
 
Method Summary
 java.lang.Object clone()
          Return a clone of this.
abstract  java.lang.Object evaluate(Phenotype phenotype)
          Evaluate this expression in the context of the passed Phenotype.
protected  java.util.SortedMap getMutators()
          Provides a SortedMap of GpMutators with their probabilities (Doubles between 0.0 and 1.0) so that #mutate(float) can choose one to do a mutation.
 java.lang.Class getParameterClass(int index)
          Note this implementation calls getParameterClasses, so make that method efficient.
protected abstract  java.util.List getParameterClasses()
           
abstract  GpTreeNode getParameterGene(int index)
           
 int getParametersLength()
          Note this implementation calls getParameterClasses, so make that method efficient.
abstract  java.lang.Class getReturnClass()
           
 int getSize()
          Note: this is expensive to call.
 void mutate(java.lang.String geneSelectionId, float probability)
          Mutate this gene in some way with the passed probability.
abstract  void setParameterGene(int index, GpTreeNode gene)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GpTreeNode

public GpTreeNode()
Method Detail

evaluate

public abstract java.lang.Object evaluate(Phenotype phenotype)
Evaluate this expression in the context of the passed Phenotype.


mutate

public void mutate(java.lang.String geneSelectionId,
                   float probability)
Mutate this gene in some way with the passed probability.

Parameters:
probability - of mutation happening.
See Also:
FunctionGene#mutate(float)

getSize

public int getSize()
Note: this is expensive to call.

Returns:
1 plus the sum of sizes of all parameter genes

clone

public java.lang.Object clone()
Return a clone of this. Override to deep clone any non-primitive fields in subclasses.

Overrides:
clone in class java.lang.Object

getMutators

protected java.util.SortedMap getMutators()
Provides a SortedMap of GpMutators with their probabilities (Doubles between 0.0 and 1.0) so that #mutate(float) can choose one to do a mutation. The map needs to look like:
0.1
a GpMutator instance with 10% chance of being used
0.2
a different GpMutator instance with 10% chance of being used
1.0
a GpMutator instance with 80% chance of being used

Load from configuration properties. [getClass().getName()].mutator.class.0 and optionally [getClass().getName()].mutator.probability.0 using: Configuration.getInstance().getInstancesProbabilities(getClass().getName() + ".mutator");

Returns:
SortedMap of probability vs mutator class, or null if no mutators for this gene

getReturnClass

public abstract java.lang.Class getReturnClass()
Returns:
the class this gene returns on evaluation

getParameterClasses

protected abstract java.util.List getParameterClasses()
Returns:
List of the Classes that this gene expects to evaluate against

getParameterClass

public java.lang.Class getParameterClass(int index)
Note this implementation calls getParameterClasses, so make that method efficient.

Parameters:
index -
Returns:
Class the return class of the parameter at the given index
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).

getParametersLength

public int getParametersLength()
Note this implementation calls getParameterClasses, so make that method efficient.

Returns:
number of parameters expected

getParameterGene

public abstract GpTreeNode getParameterGene(int index)
Returns:
the gene at the passed index, may be null
Throws:
java.lang.IndexOutOfBoundsException - for index out of range

setParameterGene

public abstract void setParameterGene(int index,
                                      GpTreeNode gene)
Parameters:
index - the index of the gene to replace
gene - the gene to replace with
Throws:
java.lang.IndexOutOfBoundsException - for index out of range

artoflife pre0.1.0-dev

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