Documentation of 'ec.gp.push.Terminal' Java class
Terminal
ec.gp.push

Class Terminal

  • All Implemented Interfaces:
    GPNodeParent, Prototype, Setup, java.io.Serializable, java.lang.Cloneable


    public class Terminal
    extends ERC
    Terminal is the leaf node in Push trees and is used to represent Push instructions of all types.

    ECJ implements Push's s-expressions as trees of nonterminals and terminals. The nonterminals are all dummy instances of the Nonterminal class. Terminals are all instances of the Terminal class.

    The nonterminals and terminals aren't actually evaluated. Instead, the tree is printed out as a lisp s-expression and sent to the Push interpreter.

    Terminals are implemented as ERCs which hold the actual Push instruction or atom as a string ('value'). There are four kinds of instructions at present:

    1. Built-in Push instructions like float.* or integer.swap
    2. Floating-point ERCs (defined by "float.erc")
    3. Integer ERCs (defined by "integer.erc")
    4. Custom Push instructions

    You specify your instructions like this:

        push.op.size = 7
        push.op.0 = float.erc
        push.op.1 = float.+
        
        # This is a custom instruction
        push.op.2 = float.print
        push.op.2.func = ec.gp.push.example.MyPushInstruction
        
        push.op.3 = float.%
        push.op.4 = float.-
        push.op.5 = float.dup
        push.op.6 = float.swap
        

    For the (at present) two kinds of ERCs, you can specify a minimum and a maximum value. Here are the defaults:

        push.op.float.min = -10
        push.op.float.max = 10
        push.op.int.min = -10
        push.op.int.max = 10
        
    The full list of Psh instructions is:

    integer.+
    integer.-
    integer./
    integer.\%
    integer.*
    integer.pow
    integer.log
    integer.=
    integer.>
    integer.*lt;
    integer.min
    integer.max
    integer.abs
    integer.neg
    integer.ln
    integer.fromfloat
    integer.fromboolean
    integer.rand
    float.+
    float.-
    float./
    float.\%
    float.*
    float.pow
    float.log
    float.=
    float.>
    float.<
    float.min
    float.max
    float.sin
    float.cos
    float.tan
    float.exp
    float.abs
    float.neg
    float.ln
    float.frominteger
    float.fromboolean
    float.rand
    boolean.=
    boolean.not
    boolean.and
    boolean.or
    boolean.xor
    boolean.frominteger
    boolean.fromfloat
    boolean.rand
    true
    false
    code.quote
    code.fromboolean
    code.frominteger
    code.fromfloat
    code.noop
    code.do*times
    code.do*count
    code.do*range
    code.=
    code.if
    code.rand
    exec.k
    exec.s
    exec.y
    exec.noop
    exec.do*times
    exec.do*count
    exec.do*range
    exec.=
    exec.if
    exec.rand
    input.index
    input.inall
    input.inallrev
    input.stackdepth
    frame.push
    frame.pop

    Parameters

    base.op.size
    int >= 1
    (Number of instructions in Push's internal "instruction set")
    base.op.i
    String
    (Name of instruction i)
    base.op.i.func
    classname, inherits and != ec.gp.push.PushInstruction
    (PushInstruction corresponding to instruction i, if it is a custom instruction)
    base.op.float.min
    float
    (Minimum value for a Push floating-point ERC)
    base.op.float.max
    float
    (Maximum value for a Push floating-point ERC)
    base.op.int.min
    int
    (Minimum value for a Push integer ERC)
    base.op.int.max
    int
    (Maximum value for a Push integer ERC)

    Default Base
    gp.push

    See Also:
    Serialized Form
    • Field Detail

      • P_NUM_INSTRUCTIONS

        public static final java.lang.String P_NUM_INSTRUCTIONS
        See Also:
        Constant Field Values
      • ERC_NAMES

        public static final java.lang.String[] ERC_NAMES
      • minFloatERC

        public static double minFloatERC
      • maxFloatERC

        public static double maxFloatERC
      • minIntegerERC

        public static int minIntegerERC
      • maxIntegerERC

        public static int maxIntegerERC
      • instructions

        public java.lang.String[] instructions
        Names of all the Push instructions I can be set to. This includes names for custom PushInstructions.
      • customInstructions

        public PushInstruction[] customInstructions
        A list of custom PushInstructions I can be set to.
      • indices

        public int[] indices
        For each PushInstruction, a pointer into instructions which gives the name of that instruction. Note that some instructions in instructions are built-in Push instructions and will have nothing pointing to them.
    • Constructor Detail

      • Terminal

        public Terminal()
    • Method Detail

      • name

        public java.lang.String name()
        Description copied from class: ERC
        Returns the lowercase "name" of this ERC function class, some simple, short name which distinguishes this class from other ERC function classes you're using. If you have more than one ERC function, you need to distinguish them here. By default the value is "ERC", which works fine for a single ERC function in the function set. Whatever the name is, it should generally only have letters, numbers, or hyphens or underscores in it. No whitespace or other characters.
        Overrides:
        name in class ERC
      • expectedChildren

        public int expectedChildren()
        Description copied from class: ERC
        Usually ERCs don't have children, and this default implementation makes certain of it. But if you want to override this, you're welcome to.
        Overrides:
        expectedChildren in class ERC
      • toStringForHumans

        public java.lang.String toStringForHumans()
        Description copied from class: ERC
        You might want to override this to return a special human-readable version of the erc value; otherwise this defaults to toString(); This should be something that resembles a LISP atom. If a simple number or other object won't suffice, you might use something that begins with name() + [ + ... + ]
        Overrides:
        toStringForHumans in class ERC
      • 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
      • 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
      • nodeEquals

        public boolean nodeEquals(GPNode other)
        Description copied from class: ERC
        Implement this to do ERC-to-ERC comparisons.
        Specified by:
        nodeEquals in class ERC
      • encode

        public java.lang.String encode()
        Description copied from class: ERC
        Encodes data from the ERC, using ec.util.Code.
        Specified by:
        encode in class ERC
      • decode

        public boolean decode(DecodeReturn dret)
        Description copied from class: ERC
        Decodes data into the ERC from dret. Return true if you sucessfully decoded, false if you didn't. Don't increment dret.pos's value beyond exactly what was needed to decode your ERC. If you fail to decode, you should make sure that the position and data in the dret are exactly as they were originally.
        Overrides:
        decode in class ERC
      • resetNode

        public void resetNode(EvolutionState state,
                              int thread)
        Description copied from class: ERC
        Remember to override this to randomize your ERC after it has been cloned. The prototype will not ever receive this method call.
        Specified by:
        resetNode in class ERC
      • 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 && x;
            return;
            }
                
        Specified by:
        eval in class GPNode

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.