Class GPNodeBuilder
- All Implemented Interfaces:
Prototype,Setup,Serializable,Cloneable
- Direct Known Subclasses:
KozaBuilder,PTC1,PTC2,PushBuilder,RandomBranch,RandTree,Uniform
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 <= double <= 1.0, or undefined |
(probability of choosing size n. See discussion above) |
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intintthe minium possible size -- if unused, it's 0intstatic final intProduces a new rooted tree of GPNodes whose root's return type is swap-compatible with type.static final Stringstatic final Stringstatic final Stringstatic final Stringdouble[]the maximum possible size -- if unused, it's 0 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancanPick()Returns true if some size distribution (either minSize and maxSize, or sizeDistribution) is set up by the user in order to pick sizes randomly.clone()Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.protected voiderrorAboutNoNodeWithType(GPType type, EvolutionState state) Issues a fatal error that no node (nonterminal or terminal) was found with a return type of the given type, and that an algorithm had requested one.abstract GPNodenewRootedTree(EvolutionState state, GPType type, int thread, GPNodeParent parent, GPFunctionSet set, int argposition, int requestedSize) intpickSize(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.voidsetup(EvolutionState state, Parameter base) Sets up the object by reading it from the parameters stored in state, built off of the parameter base base.protected booleanwarnAboutNonterminal(boolean test, GPType type, boolean fail, EvolutionState state) If the given test is true, issues a warning that no terminal was found with a return type of the given type, and that an algorithm had requested one.protected voidwarnAboutNonTerminalWithType(GPType type, boolean fail, EvolutionState state) Issues a warning that no nonterminal was found with a return type of the given type, and that an algorithm had requested one.protected voidwarnAboutNoTerminalWithType(GPType type, boolean fail, EvolutionState state) Issues a warning that no terminal was found with a return type of the given type, and that an algorithm had requested one.Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ec.Prototype
defaultBase
-
Field Details
-
NOSIZEGIVEN
public static final int NOSIZEGIVENProduces a new rooted tree of GPNodes whose root's return type is swap-compatible with type. When you build a brand-new tree out of GPNodes cloned from the prototypes stored in the GPNode[] arrays, you must remember to call resetNode() on each cloned GPNode. This gives ERCs a chance to randomize themselves and set themselves up.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.
- See Also:
-
CHECK_BOUNDARY
public static final int CHECK_BOUNDARY- See Also:
-
P_MINSIZE
- See Also:
-
P_MAXSIZE
- See Also:
-
P_NUMSIZES
- See Also:
-
P_SIZE
- See Also:
-
minSize
public int minSize -
maxSize
public int maxSizethe minium possible size -- if unused, it's 0 -
sizeDistribution
public double[] sizeDistributionthe maximum possible size -- if unused, it's 0
-
-
Constructor Details
-
GPNodeBuilder
public GPNodeBuilder()
-
-
Method Details
-
canPick
public 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. -
pickSize
Assuming that either minSize and maxSize, or sizeDistribution, is defined, picks a random size from minSize...maxSize inclusive, or randomly from sizeDistribution. -
clone
Description copied from interface:PrototypeCreates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.Typically this should be a full "deep" clone. However, you may share certain elements with other objects rather than clone hem, depending on the situation:
- If you hold objects which are shared with other instances, don't clone them.
- If you hold objects which must be unique, clone them.
- If you hold objects which were given to you as a gesture of kindness, and aren't owned by you, you probably shouldn't clone them.
- DON'T attempt to clone: Singletons, Cliques, or Populations, or Subpopulation.
- Arrays are not cloned automatically; you may need to clone an array if you're not sharing it with other instances. Arrays have the nice feature of being copyable by calling clone() on them.
Implementations.
- If no ancestor of yours implements clone(), and you have no need to do clone deeply, and you are abstract, then you should not declare clone().
- If no ancestor of yours implements clone(),
and you have no need to do clone deeply,
and you are not abstract, then you should implement
it as follows:
public Object clone() { try { return super.clone(); } catch ((CloneNotSupportedException e) { throw new InternalError(); } // never happens } - If no ancestor of yours implements clone(), but you
need to deep-clone some things, then you should implement it
as follows:
public Object clone() { try { MyObject myobj = (MyObject) (super.clone()); // put your deep-cloning code here... } catch ((CloneNotSupportedException e) { throw new InternalError(); } // never happens return myobj; } - If an ancestor has implemented clone(), and you also need
to deep clone some things, then you should implement it as follows:
public Object clone() { MyObject myobj = (MyObject) (super.clone()); // put your deep-cloning code here... return myobj; }
-
setup
Description copied from interface:PrototypeSets 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.
-
newRootedTree
public abstract GPNode newRootedTree(EvolutionState state, GPType type, int thread, GPNodeParent parent, GPFunctionSet set, int argposition, int requestedSize) -
warnAboutNoTerminalWithType
Issues a warning that no terminal was found with a return type of the given type, and that an algorithm had requested one. If fail is true, then a fatal is issued rather than a warning. The warning takes the form of a one-time big explanatory message, followed by a one-time-per-type message. -
warnAboutNonterminal
protected boolean warnAboutNonterminal(boolean test, GPType type, boolean fail, EvolutionState state) If the given test is true, issues a warning that no terminal was found with a return type of the given type, and that an algorithm had requested one. If fail is true, then a fatal is issued rather than a warning. The warning takes the form of a one-time big explanatory message, followed by a one-time-per-type message. Returns the value of the test. This form makes it easy to insert warnings into if-statements. -
warnAboutNonTerminalWithType
Issues a warning that no nonterminal was found with a return type of the given type, and that an algorithm had requested one. If fail is true, then a fatal is issued rather than a warning. The warning takes the form of a one-time big explanatory message, followed by a one-time-per-type message. -
errorAboutNoNodeWithType
Issues a fatal error that no node (nonterminal or terminal) was found with a return type of the given type, and that an algorithm had requested one.
-