Package ec.gp

# Class ADFArgument

java.lang.Object
ec.gp.GPNode
ec.gp.ADFArgument

All Implemented Interfaces:
  `GPNodeParent`, `Prototype`, `Setup`, `Serializable`, `Cloneable`

public class ADFArgument extends GPNode
An ADFArgument is a GPNode which represents an ADF's argument terminal, its counterpart which returns argument values in its associated function tree. In lil-gp this is called an ARG node.

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

See Also:
  - `ADF`
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `int`
  `argument`
  `String`
  `name`
  The "function name" of the ADFArgument, to distinguish it from other GP functions you might provide.
  `static final String`
  `P_ADFARGUMENT`
  `static final String`
  `P_ARGUMENT`
  `static final String`
  `P_FUNCTIONNAME`

  ### Fields inherited from class ec.gp.GPNode

  `argposition, children, CHILDREN_UNKNOWN, constraints, GPNODEPRINTTAB, MAXPRINTBYTES, NODESEARCH_ALL, NODESEARCH_NONTERMINALS, NODESEARCH_TERMINALS, P_NODE, P_NODECONSTRAINTS, parent`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ADFArgument()`

- ## Method Summary

  Modifier and Type
  Method
  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.
  `String`
  `name()`
  Returns a Lisp-like atom for the node and any nodes of the same class.
  `void`
  `readNode(EvolutionState state, 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.
  `String`
  `toString()`
  Returns a Lisp-like atom for the node which can be read in again by computer.
  `void`
  `writeNode(EvolutionState state, 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.

  ### Methods inherited from class ec.gp.GPNode

  `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`

  ### Methods inherited from class java.lang.Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### P_ADFARGUMENT

    public static final String P_ADFARGUMENT
    See Also:
      - Constant Field Values

  - ### P_ARGUMENT

    public static final String P_ARGUMENT
    See Also:
      - Constant Field Values

  - ### P_FUNCTIONNAME

    public static final String P_FUNCTIONNAME
    See Also:
      - Constant Field Values

  - ### argument

    public int argument

  - ### name

    public String name
    The "function name" of the ADFArgument, to distinguish it from other GP functions you might provide.

- ## Constructor Details

  - ### ADFArgument

    public ADFArgument()

- ## Method Details

  - ### name

    public String name()
    Description copied from class: `GPNode`
    Returns a Lisp-like atom for the node and any nodes of the same class. This will almost always be identical to the result of toString() (and the default does exactly this), but for ERCs it'll be different: toString will include the encoded constant data, whereas name() will not include this information and will be the same for all ERCs of this type. If two nodes are nodeEquivalentTo(...) each other, then they will have the same name(). If two nodes are nodeEquals(...) each other, then they will have the same toString().
    Overrides:
      `name` in class `GPNode`

  - ### expectedChildren

    public int expectedChildren()
    Description copied from class: `GPNode`
    Returns the number of children this node expects to have. This method is only called by the default implementation of checkConstraints(...), and by default it returns CHILDREN_UNKNOWN. You can override this method to return a value >= 0, which will be checked for in the default checkConstraints(...), or you can leave this method alone and override checkConstraints(...) to check for more complex constraints as you see fit.
    Overrides:
      `expectedChildren` in class `GPNode`

  - ### defaultBase

    public Parameter defaultBase()
    Description copied from class: `GPNode`
    The default base for GPNodes -- defined even though GPNode is abstract so you don't have to in subclasses.
    Specified by:
      `defaultBase` in interface `Prototype`
    Overrides:
      `defaultBase` in class `GPNode`

  - ### toString

    public String toString()
    Description copied from class: `GPNode`
    Returns a Lisp-like atom for the node which can be read in again by computer. If you need to encode an integer or a float or whatever for some reason (perhaps if it's an ERC), you should use the ec.util.Code library.
    Specified by:
      `toString` in class `GPNode`

  - ### setup

    public void setup(EvolutionState state, Parameter base)
    Description copied from class: `GPNode`
    Sets up a prototypical GPNode with those features all nodes of that prototype share, and nothing more. So no filled-in children, no argposition, no parent. Yet. This must be called after the GPTypes and GPNodeConstraints have been set up. Presently they're set up in GPInitializer, which gets called before this does, so we're safe. You should override this if you need to load some special features on a per-function basis. Note that base hangs off of a function set, so this method may get called for different instances in the same GPNode class if they're being set up as prototypes for different GPFunctionSets. If you absolutely need some global base, then you should use something hanging off of GPDefaults.base(). The ultimate caller of this method must guarantee that he will eventually call state.output.exitIfErrors(), so you can freely use state.output.error instead of state.output.fatal(), which will help a lot.
    Specified by:
      `setup` in interface `Prototype`
    Specified by:
      `setup` in interface `Setup`
    Overrides:
      `setup` in class `GPNode`

  - ### writeNode

    public void writeNode(EvolutionState state, DataOutput dataOutput) throws IOException
    Description copied from class: `GPNode`
    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. The default version of this method does nothing.
    Overrides:
      `writeNode` in class `GPNode`
    Throws:
      `IOException`

  - ### readNode

    public void readNode(EvolutionState state, DataInput dataInput) throws IOException
    Description copied from class: `GPNode`
    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. The default version of this method does nothing.
    Overrides:
      `readNode` in class `GPNode`
    Throws:
      `IOException`

  - ### eval

    public void eval(EvolutionState state, int thread, GPData input, ADFStack stack, GPIndividual individual, Problem problem)
    Description copied from class: `GPNode`
    Evaluates the node with the given thread, state, individual, problem, and stack. Your random number generator will be state.random[thread]. The node should, as appropriate, evaluate child nodes with these same items passed to eval(...).

    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 invalid input: '&'invalid input: '&' x;
            return;
            }

    Specified by:
      `eval` in class `GPNode`