ec.gp
Class GPProblem

java.lang.Object
  |
  +--ec.gp.GPProblem

public abstract class GPProblem
extends java.lang.Object
implements Problem

A GPProblem is a Problem which is meant to efficiently handle GP evaluation. GPProblems hold one ADFStack, which is used to evaluate a large number of trees without having to be garbage-collected and reallocated. Be sure to call stack.reset() after each tree evaluation.

Parameters
base.stack
classname, inherits or = ec.ADFStack
(the class for the GPProblem's ADF Stack)
base.data
classname, inherits and != ec.GPData
(the class for the GPProblem's basic GPData type)

Default Base
gp.problem

Parameter bases
base.stack
(stack)
base.data
(data)

See Also:
Serialized Form

Field Summary
 GPData data
          The GPProblems' GPData
static java.lang.String P_DATA
           
static java.lang.String P_GPPROBLEM
           
static java.lang.String P_STACK
           
 ADFStack stack
          The GPProblem's stack
 
Constructor Summary
GPProblem()
           
 
Method Summary
 Parameter defaultBase()
          GPProblem defines a default base so your subclass doesn't absolutely have to.
 void describe(Individual[] ind, EvolutionState state, int threadnum, int log, int verbosity)
          "Reevaluates" a set of individuals together, for the purpose of printing out interesting facts about the individuals in the context of the Problem, and logs the results.
 java.lang.Object protoClone()
          Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.
 java.lang.Object protoCloneSimple()
          This should be implemented in a the top-level Prototype ONLY; in fact, it should probably be declared final.
 void setup(EvolutionState state, Parameter base)
          Sets up the object by reading it from the parameters stored in state, built off of the parameter base base.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

P_GPPROBLEM

public static final java.lang.String P_GPPROBLEM

P_STACK

public static final java.lang.String P_STACK

P_DATA

public static final java.lang.String P_DATA

stack

public ADFStack stack
The GPProblem's stack

data

public GPData data
The GPProblems' GPData
Constructor Detail

GPProblem

public GPProblem()
Method Detail

defaultBase

public Parameter defaultBase()
GPProblem defines a default base so your subclass doesn't absolutely have to.

setup

public void setup(EvolutionState state,
                  Parameter base)
Description copied from interface: Prototype
Sets up the object by reading it from the parameters stored in state, built off of the parameter base base. If an ancestor implements this method, be sure to call super.setup(state,base); before you do anything else.

For prototypes, setup(...) is typically called once for the prototype instance; cloned instances do not receive the setup(...) call. setup(...) may be called more than once; the only guarantee is that it will get called at least once on an instance or some "parent" object from which it was ultimately cloned.


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.


protoCloneSimple

public final java.lang.Object protoCloneSimple()
Description copied from interface: Prototype
This should be implemented in a the top-level Prototype ONLY; in fact, it should probably be declared final. It should be implemented as follows:

public final Object protoCloneSimple()
{
try { return protoClone(); }
catch (CloneNotSupportedException e) 
{ throw new InternalError(); } // never happens
} 

describe

public void describe(Individual[] ind,
                     EvolutionState state,
                     int threadnum,
                     int log,
                     int verbosity)
Description copied from interface: Problem
"Reevaluates" a set of individuals together, for the purpose of printing out interesting facts about the individuals in the context of the Problem, and logs the results. This might be called to print out facts about the best individuals in the population, for example.
Specified by:
describe in interface Problem