public class ADFArgument extends GPNode
Obviously, if you have Argument Terminals in a tree, that tree must be only callable by ADFs and ADMs, otherwise the Argument Terminals won't have anything to return. Furthermore, you must make sure that you don't have an Argument Terminal in a tree whose number is higher than the smallest arity (number of arguments) of a calling ADF or ADM.
Parameters
base.arg int >= 0 |
(The related argument position for the ADF Argument Node in the associated ADF) |
Default Base
gp.adf-argument
ADF
,
Serialized FormModifier and Type | Field and Description |
---|---|
int |
argument |
java.lang.String |
name
The "function name" of the ADFArgument, to distinguish it from other GP
functions you might provide.
|
static java.lang.String |
P_ADFARGUMENT |
static java.lang.String |
P_ARGUMENT |
static java.lang.String |
P_FUNCTIONNAME |
argposition, children, CHILDREN_UNKNOWN, constraints, GPNODEPRINTTAB, MAXPRINTBYTES, NODESEARCH_ALL, NODESEARCH_NONTERMINALS, NODESEARCH_TERMINALS, P_NODE, P_NODECONSTRAINTS, parent
Constructor and Description |
---|
ADFArgument() |
Modifier and Type | Method and Description |
---|---|
Parameter |
defaultBase()
The default base for GPNodes -- defined even though
GPNode is abstract so you don't have to in subclasses.
|
void |
eval(EvolutionState state,
int thread,
GPData input,
ADFStack stack,
GPIndividual individual,
Problem problem)
Evaluates the node with the given thread, state, individual, problem, and stack.
|
int |
expectedChildren()
Returns the number of children this node expects to have.
|
java.lang.String |
name()
Returns a Lisp-like atom for the node and any nodes of the same class.
|
void |
readNode(EvolutionState state,
java.io.DataInput dataInput)
Override this to read any additional node-specific information from dataInput besides: the number of arguments,
the specific node class, the children, and the parent.
|
void |
setup(EvolutionState state,
Parameter base)
Sets up a prototypical GPNode with those features all nodes of that
prototype share, and nothing more.
|
java.lang.String |
toString()
Returns a Lisp-like atom for the node which can be read in again by computer.
|
void |
writeNode(EvolutionState state,
java.io.DataOutput dataOutput)
Override this to write any additional node-specific information to dataOutput besides: the number of arguments,
the specific node class, the children, and the parent.
|
atDepth, checkConstraints, clone, cloneReplacing, cloneReplacing, cloneReplacing, cloneReplacingAtomic, cloneReplacingAtomic, cloneReplacingNoSubclone, constraints, contains, depth, errorInfo, iterator, iterator, iterator, lightClone, makeCTree, makeGraphvizSubtree, makeGraphvizTree, makeLatexTree, makeLispTree, makeLispTree, nodeEquals, nodeEquivalentTo, nodeHashCode, nodeInPosition, nodeInPosition, numNodes, numNodes, parentType, pathLength, printNode, printNode, printNode, printNodeForHumans, printNodeForHumans, printRootedTree, printRootedTree, printRootedTree, printRootedTreeForHumans, printRootedTreeForHumans, readNode, readRootedTree, readRootedTree, replaceWith, resetNode, rootedTreeEquals, rootedTreeHashCode, rootParent, swapCompatibleWith, toStringForError, toStringForHumans, writeRootedTree
public static final java.lang.String P_ADFARGUMENT
public static final java.lang.String P_ARGUMENT
public static final java.lang.String P_FUNCTIONNAME
public int argument
public java.lang.String name
public java.lang.String name()
GPNode
public int expectedChildren()
GPNode
expectedChildren
in class GPNode
public Parameter defaultBase()
GPNode
defaultBase
in interface Prototype
defaultBase
in class GPNode
public java.lang.String toString()
GPNode
public void setup(EvolutionState state, Parameter base)
GPNode
public void writeNode(EvolutionState state, java.io.DataOutput dataOutput) throws java.io.IOException
GPNode
public void readNode(EvolutionState state, java.io.DataInput dataInput) throws java.io.IOException
GPNode
public void eval(EvolutionState state, int thread, GPData input, ADFStack stack, GPIndividual individual, Problem problem)
GPNode
About input: input is special; it is how data is passed between parent and child nodes. If children "receive" data from their parent node when it evaluates them, they should receive this data stored in input. If (more likely) the parent "receives" results from its children, it should pass them an input object, which they'll fill out, then it should check this object for the returned value.
A tree is typically evaluated by dropping a GPData into the root. When the root returns, the resultant input should hold the return value.
In general, you should not be creating new GPDatas. If you think about it, in most conditions (excepting ADFs and ADMs) you can use and reuse input for most communications purposes between parents and children.
So, let's say that your GPNode function implements the boolean AND function,
and expects its children to return return boolean values (as it does itself).
You've implemented your GPData subclass to be, uh, BooleanData, which
looks like
public class BooleanData extends GPData
{
public boolean result;
public GPData copyTo(GPData gpd)
{
((BooleanData)gpd).result = result;
}
}
...so, you might implement your eval(...) function as follows:
public void eval(final EvolutionState state,
final int thread,
final GPData input,
final ADFStack stack,
final GPIndividual individual,
final Problem problem
{
BooleanData dat = (BooleanData)input;
boolean x;
// evaluate the first child
children[0].eval(state,thread,input,stack,individual,problem);
// store away its result
x = dat.result;
// evaluate the second child
children[1].eval(state,thread,input,stack,individual,problem);
// return (in input) the result of the two ANDed
dat.result = dat.result && x;
return;
}