ec.gp
Class GPFuncInfo

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

public class GPFuncInfo
extends java.lang.Object
implements Prototype

GPFuncInfo is a Prototype wrapper object which holds a single GPNode and is stored in arrays keyed by the GPNode's type. The purpose of GPFuncInfo is to provide a hook for future development to add "facts" about GPNode prototypes as they're stored away waiting to be cloned into trees, without having to modify GPNode itself, which would be brittle since it's the superclass of all GP function nodes.

Default Base
gp.func-info

See Also:
Serialized Form

Field Summary
 GPNode node
          The stored node
static java.lang.String P_GPFUNCINFO
           
 
Constructor Summary
GPFuncInfo()
           
 
Method Summary
 java.util.Hashtable arrange(java.util.Hashtable hash)
          Override this to rearrange hash's contents as you see fit.
 Parameter defaultBase()
          Returns the default base for this prototype.
 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_GPFUNCINFO

public static final java.lang.String P_GPFUNCINFO

node

public GPNode node
The stored node
Constructor Detail

GPFuncInfo

public GPFuncInfo()
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(...).
Specified by:
defaultBase in interface Prototype

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.

Specified by:
setup in interface Prototype

arrange

public java.util.Hashtable arrange(java.util.Hashtable hash)
Override this to rearrange hash's contents as you see fit. hash contains arrays of GPFuncInfo objects of your class, keyed by a GPType (there's one array for every GPType there is). For example, you might sort elements in each array by some probability of occurrence, if you've subclassed GPFuncInfo to work with a GPNodeGenerator of some sort that requires this. This method only gets called on prototypes, though it might get called more than once, and with different values for hash. Return the resultant hashtable (or if you've changed it to some other hashtable, return that).

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.

Specified by:
protoClone in interface Prototype

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
} 
Specified by:
protoCloneSimple in interface Prototype