ec.gp
Class GPIndividual

java.lang.Object
  |
  +--ec.Individual
        |
        +--ec.gp.GPIndividual
All Implemented Interfaces:
java.lang.Cloneable, Prototype, java.io.Serializable, Setup

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.

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 EVALUATED_PREAMBLE
           
static java.lang.String P_INDIVIDUAL
           
static java.lang.String P_NUMTREES
           
static java.lang.String P_TREE
           
 GPTree[] trees
           
 
Fields inherited from class ec.Individual
evaluated, fitness, species
 
Constructor Summary
GPIndividual()
           
 
Method Summary
 Individual deepClone()
          Guaranteed DEEP-CLONES the individual.
 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.
 void printIndividual(EvolutionState state, int log, int verbosity)
          Prints the individual in a way that it can be read in again by computer.
 void printIndividual(EvolutionState state, java.io.PrintWriter writer)
          Prints the individual in a way that it can be read in again by computer.
 void printIndividualForHumans(EvolutionState state, int log, int verbosity)
          A printer for the individual in a reasonable human-readable, fashion.
 java.lang.Object protoClone()
          Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.
 void readIndividual(EvolutionState state, java.io.LineNumberReader reader)
          Reads in the individual from a form printed by printIndividual().
 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.
 
Methods inherited from class ec.Individual
protoCloneSimple
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

P_INDIVIDUAL

public static final java.lang.String P_INDIVIDUAL

P_NUMTREES

public static final java.lang.String P_NUMTREES

P_TREE

public static final java.lang.String P_TREE

EVALUATED_PREAMBLE

public static final java.lang.String EVALUATED_PREAMBLE

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.
Overrides:
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.
Overrides:
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.
Overrides:
setup in class Individual
Following copied from class: ec.Individual
See Also:
Prototype.setup(EvolutionState,Parameter)

printIndividualForHumans

public void printIndividualForHumans(EvolutionState state,
                                     int log,
                                     int verbosity)
A printer for the individual in a reasonable human-readable, fashion. The default version prints out whether the individual has been evaluated, what its fitness is, and each of its trees in turn. Don't write the species. Modify this function as you see fit.
Overrides:
printIndividualForHumans in class Individual

printIndividual

public void printIndividual(EvolutionState state,
                            int log,
                            int verbosity)
Prints the individual in a way that it can be read in again by computer. The default version prints out whether the individual has been evaluated, what its fitness is, and each of its trees in turn. Don't write the species. Modify this function as you see fit.
Overrides:
printIndividual in class Individual

printIndividual

public void printIndividual(EvolutionState state,
                            java.io.PrintWriter writer)
Prints the individual in a way that it can be read in again by computer. The default version prints out whether the individual has been evaluated, what its fitness is, and each of its trees in turn. Don't write the species. Modify this function as you see fit.
Overrides:
printIndividual in class Individual

readIndividual

public void readIndividual(EvolutionState state,
                           java.io.LineNumberReader reader)
                    throws java.io.IOException,
                           java.lang.CloneNotSupportedException
Reads in the individual from a form printed by printIndividual(). The Fitness should have already been assigned to the individual at this point. Don't read in the species, it should also get set externally by whoever calls this function.
Overrides:
readIndividual in class Individual

deepClone

public Individual deepClone()
Description copied from class: Individual
Guaranteed DEEP-CLONES the individual. You may need to override this method in Individual subclasses to guarantee this fact. Some individuals (notably GPIndividuals) do not have protoClone() deep-clone them because that is expensive. But if you need to guarantee that you have a unique individual, this is the way to do it.
Overrides:
deepClone in class Individual

protoClone

public java.lang.Object protoClone()
                            throws java.lang.CloneNotSupportedException
Description copied from interface: Prototype
Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.

The question here is whether or not this means to perform a "deep" or "light" ("shallow") clone, or something in-between. You may need to deep-clone parts of your object rather than simply copying their references, depending on the situation:

Implementations.

If you know that your superclasses will never change their protoClone() implementations, you might try inlining them in your overridden protoClone() method. But this is dangerous (though it yields a small net increase).

In general, you want to keep your deep cloning to an absolute minimum, so that you don't have to call protoClone() but one time.

The approach taken here is the fastest that I am aware of while still permitting objects to be specified at runtime from a parameter file. It would be faster to use the "new" operator; but that would require hard-coding that we can't do. Although using java.lang.Object.clone() entails an extra layer that deals with stripping away the "protected" keyword and also wrapping the exception handling (which is a BIG hit, about three times as slow as using "new"), it's still MUCH faster than using java.lang.Class.newInstance(), and also much faster than rolling our own Clone() method.

Overrides:
protoClone in class Individual

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