ec.gp
Class GPIndividual

java.lang.Object
  extended by ec.Individual
      extended by ec.gp.GPIndividual
All Implemented Interfaces:
Prototype, Setup, java.io.Serializable, java.lang.Cloneable

public class GPIndividual
extends Individual

GPIndividual is an Individual used for GP evolution runs. GPIndividuals contain, at the very least, a nonempty array of GPTrees. You can use GPIndividual directly, or subclass it to extend it as you see fit.

GPIndividuals have two clone methods: clone() and lightClone(). clone() is a deep clone method as usual. lightClone() is a light clone which does not copy the trees.

In addition to serialization for checkpointing, Individuals may read and write themselves to streams in three ways.

In general, the various readers and writers do three things: they tell the Fitness to read/write itself, they read/write the evaluated flag, and they read/write the GPTree array (by having each GPTree read/write itself). If you add instance variables to GPIndividual, you'll need to read/write those variables as well.

Parameters

base.numtrees
int >= 1
(number of trees in the GPIndividual)
base.tree.n
classname, inherits or = ec.gp.GPTree
(class of tree n in the individual)

Default Base
gp.individual

Parameter bases

base.tree.n tree n in the individual

See Also:
Serialized Form

Field Summary
static java.lang.String P_NUMTREES
           
static java.lang.String P_TREE
           
 GPTree[] trees
           
 
Fields inherited from class ec.Individual
evaluated, EVALUATED_PREAMBLE, fitness, P_INDIVIDUAL, species
 
Constructor Summary
GPIndividual()
           
 
Method Summary
 java.lang.Object clone()
          Deep-clones the GPIndividual.
 Parameter defaultBase()
          Returns the default base for this prototype.
 boolean equals(java.lang.Object ind)
          Returns true if I am genetically "equal" to ind.
 int hashCode()
          Returns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code.
 GPIndividual lightClone()
          Like clone(), but doesn't force the GPTrees to deep-clone themselves.
 void printIndividual(EvolutionState state, int log, int verbosity)
          Overridden for the GPIndividual genotype, writing each tree in turn.
 void printIndividual(EvolutionState state, java.io.PrintWriter writer)
          Overridden for the GPIndividual genotype, writing each tree in turn.
 void printIndividualForHumans(EvolutionState state, int log, int verbosity)
          Overridden for the GPIndividual genotype, writing each tree in turn.
 void readGenotype(EvolutionState state, java.io.DataInput dataInput)
          Overridden for the GPIndividual genotype.
 void readIndividual(EvolutionState state, java.io.LineNumberReader reader)
          Overridden for the GPIndividual genotype.
 void setup(EvolutionState state, Parameter base)
          Sets up a prototypical GPIndividual with those features which it shares with other GPIndividuals in its species, and nothing more.
 long size()
          Returns the "size" of the individual, namely, the number of nodes in all of its subtrees.
 void writeGenotype(EvolutionState state, java.io.DataOutput dataOutput)
          Overridden for the GPIndividual genotype.
 
Methods inherited from class ec.Individual
genotypeToString, genotypeToStringForHumans, parseGenotype, readIndividual, toString, writeIndividual
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

P_NUMTREES

public static final java.lang.String P_NUMTREES
See Also:
Constant Field Values

P_TREE

public static final java.lang.String P_TREE
See Also:
Constant Field Values

trees

public GPTree[] trees
Constructor Detail

GPIndividual

public GPIndividual()
Method Detail

defaultBase

public Parameter defaultBase()
Description copied from interface: Prototype
Returns the default base for this prototype. This should generally be implemented by building off of the static base() method on the DefaultsForm object for the prototype's package. This should be callable during setup(...).


equals

public boolean equals(java.lang.Object ind)
Description copied from class: Individual
Returns true if I am genetically "equal" to ind. This should mostly be interpreted as saying that we are of the same class and that we hold the same data. It should NOT be a pointer comparison.

Specified by:
equals in class Individual

hashCode

public int hashCode()
Description copied from class: Individual
Returns a hashcode for the individual, such that individuals which are equals(...) each other always return the same hash code.

Specified by:
hashCode in class Individual

setup

public void setup(EvolutionState state,
                  Parameter base)
Sets up a prototypical GPIndividual with those features which it shares with other GPIndividuals in its species, and nothing more.

Specified by:
setup in interface Prototype
Specified by:
setup in interface Setup
Overrides:
setup in class Individual

printIndividualForHumans

public void printIndividualForHumans(EvolutionState state,
                                     int log,
                                     int verbosity)
Overridden for the GPIndividual genotype, writing each tree in turn.

Overrides:
printIndividualForHumans in class Individual

printIndividual

public void printIndividual(EvolutionState state,
                            int log,
                            int verbosity)
Overridden for the GPIndividual genotype, writing each tree in turn.

Overrides:
printIndividual in class Individual

printIndividual

public void printIndividual(EvolutionState state,
                            java.io.PrintWriter writer)
Overridden for the GPIndividual genotype, writing each tree in turn.

Overrides:
printIndividual in class Individual

writeGenotype

public void writeGenotype(EvolutionState state,
                          java.io.DataOutput dataOutput)
                   throws java.io.IOException
Overridden for the GPIndividual genotype.

Overrides:
writeGenotype in class Individual
Throws:
java.io.IOException

readGenotype

public void readGenotype(EvolutionState state,
                         java.io.DataInput dataInput)
                  throws java.io.IOException
Overridden for the GPIndividual genotype.

Overrides:
readGenotype in class Individual
Throws:
java.io.IOException

readIndividual

public void readIndividual(EvolutionState state,
                           java.io.LineNumberReader reader)
                    throws java.io.IOException
Overridden for the GPIndividual genotype.

Overrides:
readIndividual in class Individual
Throws:
java.io.IOException

clone

public java.lang.Object clone()
Deep-clones the GPIndividual. Note that you should not deep-clone the prototypical GPIndividual stored in GPSpecies: they contain blank GPTrees with null roots, and this method, which calls GPTree.clone(), will produce a NullPointerException as a result. Instead, you probably want to use GPSpecies.newIndividual(...) if you're thinking of playing with the prototypical GPIndividual.

Specified by:
clone in interface Prototype
Overrides:
clone in class Individual

lightClone

public GPIndividual lightClone()
Like clone(), but doesn't force the GPTrees to deep-clone themselves.


size

public long size()
Returns the "size" of the individual, namely, the number of nodes in all of its subtrees.

Overrides:
size in class Individual