artoflife pre0.1.0-dev

org.artoflife.gp.genome
Class FunctionGene

java.lang.Object
  |
  +--org.artoflife.gp.genome.GpTreeNode
        |
        +--org.artoflife.gp.genome.FunctionGene
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable
Direct Known Subclasses:
BinaryLogicalGene, BinaryNumericGene, ComparisonGene, NumericIfGene, RootGene, UnaryLogicalGene, UnaryNumericGene

public abstract class FunctionGene
extends GpTreeNode

A gene that that returns a certain type and acts on a list of typed parameters.

Author:
Steve Meyfroidt
See Also:
Serialized Form

Field Summary
protected  java.util.List parameterGenes
          List of GpTreeNodes used as parameters for this to use when evaluating the return value.
 
Constructor Summary
FunctionGene()
          Create with all null parameter genes so use GeneFactory#getGeneTree(Class) to make a functional gene.
 
Method Summary
 java.lang.Object clone()
          Override to clone the parameter list.
 java.lang.Object evaluate(Phenotype phenotype)
          Evaluate the gene across the parameters in the context of a Phenotype.
protected abstract  java.lang.Object evaluate(Phenotype phenotype, java.util.List parameters)
           
protected static boolean getBooleanParameter(java.util.List parameters, int index)
          Convenience to return either the boolean value of a parameter or false if the parameter is missing.
protected static double getDoubleParameter(java.util.List parameters, int index)
          Convenience to return either the double value of a parameter or 0.0d if the parameter is missing.
protected static float getFloatParameter(java.util.List parameters, int index)
          Convenience to return either the float value of a parameter or 0.0f if the parameter is missing.
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.
protected abstract  java.util.List getParameterClasses()
           
 GpTreeNode getParameterGene(int index)
           
protected  void initParameterGenes()
           
 void setParameterGene(int index, GpTreeNode gene)
           
 java.lang.String toString()
           
 
Methods inherited from class org.artoflife.gp.genome.GpTreeNode
getParameterClass, getParametersLength, getReturnClass, getSize, mutate
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parameterGenes

protected java.util.List parameterGenes
List of GpTreeNodes used as parameters for this to use when evaluating the return value.

Constructor Detail

FunctionGene

public FunctionGene()
Create with all null parameter genes so use GeneFactory#getGeneTree(Class) to make a functional gene.

Method Detail

initParameterGenes

protected void initParameterGenes()

getParameterClasses

protected abstract java.util.List getParameterClasses()
Specified by:
getParameterClasses in class GpTreeNode
Returns:
List of the Classes that this gene expects to evaluate against, never null

evaluate

public java.lang.Object evaluate(Phenotype phenotype)
Evaluate the gene across the parameters in the context of a Phenotype. No parameters can be null at this point.

Specified by:
evaluate in class GpTreeNode
Returns:
the result of evaluating this gene

evaluate

protected abstract java.lang.Object evaluate(Phenotype phenotype,
                                             java.util.List parameters)

getParameterGene

public GpTreeNode getParameterGene(int index)
Specified by:
getParameterGene in class GpTreeNode
Returns:
the gene at the passed index
Throws:
java.lang.IndexOutOfBoundsException - for index out of range

setParameterGene

public void setParameterGene(int index,
                             GpTreeNode gene)
Specified by:
setParameterGene in class GpTreeNode
Parameters:
index - the index of the gene to replace
gene - the gene to replace with, may be null
Throws:
java.lang.IndexOutOfBoundsException - for index out of range

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
human-readable Scheme-like representation for debug

clone

public java.lang.Object clone()
Override to clone the parameter list.

Overrides:
clone in class GpTreeNode
Returns:
deep clone of this

getMutators

protected java.util.SortedMap getMutators()
Description copied from class: GpTreeNode
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");

Overrides:
getMutators in class GpTreeNode
Returns:
SortedMap of probability vs mutator class, or null if no mutators for this gene
See Also:
GpTreeNode.getMutators()

getBooleanParameter

protected static boolean getBooleanParameter(java.util.List parameters,
                                             int index)
Convenience to return either the boolean value of a parameter or false if the parameter is missing.

Parameters:
parameters - the List of parameters
index - which parameter?
Returns:
boolean value of parameter (false if parameter is null)

getFloatParameter

protected static float getFloatParameter(java.util.List parameters,
                                         int index)
Convenience to return either the float value of a parameter or 0.0f if the parameter is missing.

Parameters:
parameters - the List of parameters
index - which parameter?
Returns:
float value of parameter (0.0f if parameter is null)

getDoubleParameter

protected static double getDoubleParameter(java.util.List parameters,
                                           int index)
Convenience to return either the double value of a parameter or 0.0d if the parameter is missing.

Parameters:
parameters - the List of parameters
index - which parameter?
Returns:
float value of parameter (0.0d if parameter is null)

artoflife pre0.1.0-dev

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