|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ec.gp.ADFStack
ADFStack is a special data object used to hold ADF data. This object is a weird beast and takes some explaining. It consists of a main stack, a secondary "substack", and a "reserve" area (also implemented as a stack, but it doesn't have to be). The reserve is used to "recycle" objects rather than having to create then new every time.
When an ADF is evaluated, it first evaluates its children, then it calls push() on the ADFstack. push() either creates a new ADFContext, or it fetches one from the reserve if possible. It then pushes the context on the main stack, and also returns the context. The ADF fills the context's arguments with the results of its childrens' evaluation, and sets numargs to the number of arguments, then evaluates the ADF's associated function tree,
When an ADM is evaluated, it calls push() on the ADFstack. The ADM then fills the context's adm node with itself, and sets numargs to the number of children it has. Then it calls the ADM's associated function tree.
In that tree, if an argument terminal of value n is evaluated, the argument terminal calls evaluate(...) on the top context on the ADF stack and returns the result. This method does different things depending on whether the top context represented an ADF or an ADM. If it was an ADF, the context simply sets input to the value of argument n in the context's argument list, and returns input. If it was an ADM, the context pops itself off the stack and pushes itself on the substack (to set up the right context for evaluating an original child of the ADM), then evaluates child n of the ADM, then pops itself off the substack and pushes itself back on the stack to restore the context. Input is set to the evaluated results, and input is returned.
Parameters
base.context classname, inherits and != ec.gp.GPContext |
(the stack's GPContext class) |
Parameters
gp.adf-stack
Parameter bases
base.context | (context_proto) |
Field Summary | |
ADFContext |
context_proto
|
static int |
INITIAL_STACK_SIZE
|
protected int |
inReserve
|
protected int |
onStack
|
protected int |
onSubstack
|
static java.lang.String |
P_ADF
|
static java.lang.String |
P_ADFSTACK
|
static java.lang.String |
P_CONTEXT
|
protected ADFContext[] |
reserve
|
protected ADFContext[] |
stack
|
protected ADFContext[] |
substack
|
Constructor Summary | |
ADFStack()
|
Method Summary | |
Parameter |
defaultBase()
Returns the default base for this prototype. |
ADFContext |
get()
Returns an ADFContext from the stack's reserve, or creates one fresh if there are none in reserve. |
int |
moveFromSubstack(int n)
Moves n items onto the stack (popss them off the substack and pushes them onto the stack). |
int |
moveOntoSubstack(int n)
Moves n items onto the substack (pops them off the stack and pushes them onto the substack). |
int |
pop(int n)
Pops off n items from the stack, if possible. |
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. |
ADFContext |
push(ADFContext obj)
Pushes an ADFContext onto the main stack. |
void |
reset()
Pops off all items on the stack and the substack. |
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. |
ADFContext |
top(int n)
Returns the nth item in the stack (0-indexed), or null if this goes to the bottom of the stack. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String P_ADFSTACK
public static final java.lang.String P_ADF
public static final java.lang.String P_CONTEXT
public ADFContext context_proto
public static final int INITIAL_STACK_SIZE
protected int onStack
protected int onSubstack
protected int inReserve
protected ADFContext[] stack
protected ADFContext[] substack
protected ADFContext[] reserve
Constructor Detail |
public ADFStack()
Method Detail |
public Parameter defaultBase()
Prototype
defaultBase
in interface Prototype
public void setup(EvolutionState state, Parameter base)
Prototype
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.
setup
in interface Prototype
public java.lang.Object protoClone() throws java.lang.CloneNotSupportedException
Prototype
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.
public Object protoClone() throws CloneNotSupportedException
{
return super.clone();
}
public Object protoClone() throws CloneNotSupportedException
{
myobj = (MyObject) (super.clone());
// put your deep-cloning code here...
// ...you should use protoClone and not
// protoCloneSimple to clone subordinate objects...
return myobj;
}
public Object protoClone() throws CloneNotSupportedException
{
MyObject myobj = (MyObject)(super.protoClone());
// put your deep-cloning code here...
// ...you should use protoClone and not
// protoCloneSimple to clone subordinate objects...
return myobj;
}
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.
protoClone
in interface Prototype
public final java.lang.Object protoCloneSimple()
Prototype
public final Object protoCloneSimple()
{
try { return protoClone(); }
catch (CloneNotSupportedException e)
{ throw new InternalError(); } // never happens
}
protoCloneSimple
in interface Prototype
public final ADFContext get()
public final ADFContext push(ADFContext obj)
public final int pop(int n)
public final ADFContext top(int n)
public final int moveOntoSubstack(int n)
public final int moveFromSubstack(int n)
public final void reset()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |