|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ec.gp.GPNodeBuilder
GPNodeBuilder is a Prototype which defines the superclass for objects which create ("grow") GP trees, whether for population initialization, subtree mutation, or whatnot. It defines a single abstract method, newRootedTree(...), which must be implemented to grow the tree.
GPNodeBuilder also provides some facilities for user-specification of probabilities of various tree sizes, which the tree builder can use as it sees fit (or totally ignore). There are two such facilities. First, the user might specify a minimum and maximum range for tree sizes to be picked from; trees would likely be picked uniformly from this range. Second, the user might specify an array, num-sizes long, of probabilities of tree sizes, in order to give a precise probability distribution.
Parameters
base.min-size int >= 1, or undefined |
(smallest valid size, see discussion above) |
base.max-size int >= min-size, or undefined |
(largest valid size, see discussion above) |
base.num-sizes int >= 1, or underfined |
(number of sizes in the size distribution, see discussion above) |
base.size.n 0.0 <= float <= 1.0, or undefined |
(probability of choosing size n. See discussion above) |
Field Summary | |
static int |
CHECK_BOUNDARY
|
int |
maxSize
the minium possible size -- if unused, it's 0 |
int |
minSize
|
static int |
NOSIZEGIVEN
Produces a new rooted tree of GPNodes whose root's return type is swap-compatible with type. |
static java.lang.String |
P_MAXSIZE
|
static java.lang.String |
P_MINSIZE
|
static java.lang.String |
P_NUMSIZES
|
static java.lang.String |
P_SIZE
|
float[] |
sizeDistribution
the maximum possible size -- if unused, it's 0 |
Constructor Summary | |
GPNodeBuilder()
|
Method Summary | |
boolean |
canPick()
Returns true if some size distribution (either minSize and maxSize, or sizeDistribution) is set up by the user in order to pick sizes randomly. |
abstract GPNode |
newRootedTree(EvolutionState state,
GPType type,
int thread,
GPNodeParent parent,
GPFunctionSet set,
int argposition,
int requestedSize)
|
int |
pickSize(EvolutionState state,
int thread)
Assuming that either minSize and maxSize, or sizeDistribution, is defined, picks a random size from minSize...maxSize inclusive, or randomly from sizeDistribution. |
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 |
public static final int NOSIZEGIVEN
requestedSize is an optional argument which differs based on the GPNodeBuilder used. Typically it is set to a tree size that the calling method wants the GPNodeBuilder to produce; the GPNodeBuilder is not obligated to produce a tree of this size, but it should attempt to interpret this argument as appropriate for the given algorithm. To indicate that you don't care what size the tree should be, you can pass NOSIZEGIVEN. However if the algorithm requires you to provide a size, it will generate a fatal error to let you know.
public static final int CHECK_BOUNDARY
public static final java.lang.String P_MINSIZE
public static final java.lang.String P_MAXSIZE
public static final java.lang.String P_NUMSIZES
public static final java.lang.String P_SIZE
public int minSize
public int maxSize
public float[] sizeDistribution
Constructor Detail |
public GPNodeBuilder()
Method Detail |
public boolean canPick()
public int pickSize(EvolutionState state, int thread)
public java.lang.Object protoClone() throws java.lang.CloneNotSupportedException
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.
public final java.lang.Object protoCloneSimple()
public final Object protoCloneSimple()
{
try { return protoClone(); }
catch (CloneNotSupportedException e)
{ throw new InternalError(); } // never happens
}
public void setup(EvolutionState state, Parameter base)
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.
public abstract GPNode newRootedTree(EvolutionState state, GPType type, int thread, GPNodeParent parent, GPFunctionSet set, int argposition, int requestedSize) throws java.lang.CloneNotSupportedException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |