ec.app.sequence.func
Class IntegerTerminal

java.lang.Object
  extended by ec.gp.GPNode
      extended by ec.gp.ERC
          extended by ec.app.sequence.func.IntegerTerminal
All Implemented Interfaces:
ec.gp.GPNodeParent, ec.Prototype, ec.Setup, java.io.Serializable, java.lang.Cloneable

public class IntegerTerminal
extends ec.gp.ERC

This is an Integer based ERC, for generating Positions. It will generate Uniform Random Integers between maxPosition and minPosition. If maxPosition = 140, minPosition =0, it will generate Positional Features. If maxPosition = 140, minPosition = 60, it will generate only in a downstream of [-60,+80] sequence, simillarly if maxPosition =60, minPosition =0, it will generate in upstream.

Author:
udaykamath
See Also:
Serialized Form

Field Summary
 
Fields inherited from class ec.gp.GPNode
argposition, children, constraints, GPNODEPRINTTAB, MAXPRINTBYTES, NODESEARCH_ALL, NODESEARCH_CUSTOM, NODESEARCH_NONTERMINALS, NODESEARCH_TERMINALS, P_NODE, P_NODECONSTRAINTS, parent, SITUATION_MUTATION, SITUATION_NEWIND
 
Constructor Summary
IntegerTerminal()
           
 
Method Summary
 void checkConstraints(ec.EvolutionState state, int tree, ec.gp.GPIndividual typicalIndividual, ec.util.Parameter individualBase)
          Usually ERCs don't have children, and this default implementation makes certain of it.
 boolean decode(ec.util.DecodeReturn dret)
          Decodes data into the ERC from dret.
 java.lang.String encode()
          Encodes data from the ERC, using ec.util.Code.
 void eval(ec.EvolutionState state, int thread, ec.gp.GPData input, ec.gp.ADFStack stack, ec.gp.GPIndividual individual, ec.Problem problem)
          Evaluates the node with the given thread, state, individual, problem, and stack.
 int getRandom(ec.EvolutionState state, int thread)
           
 java.lang.String name()
          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.
 boolean nodeEquals(ec.gp.GPNode node)
          Implement this to do ERC-to-ERC comparisons.
 int nodeHashCode()
          Implement this to hash ERCs, along with other nodes, in such a way that two "equal" ERCs will usually hash to the same value.
 void readNode(ec.EvolutionState state, java.io.DataInput dataInput)
          To successfully read from a DataOutput, you must override this to read your specific ERC data in.
 void resetNode(ec.EvolutionState state, int thread)
          Remember to override this to randomize your ERC after it has been cloned.
 void setup(ec.EvolutionState state, ec.util.Parameter base)
          Sets up a prototypical GPNode with those features all nodes of that prototype share, and nothing more.
 java.lang.String toString()
          This defaults to simply name() + "[" + encode() + "]".
 void writeNode(ec.EvolutionState state, java.io.DataOutput dataOutput)
          To successfully write to a DataOutput, you must override this to write your specific ERC data out.
 
Methods inherited from class ec.gp.ERC
mutateERC, readNode, toStringForHumans
 
Methods inherited from class ec.gp.GPNode
atDepth, clone, cloneReplacing, cloneReplacing, cloneReplacing, cloneReplacingAtomic, cloneReplacingAtomic, cloneReplacingNoSubclone, constraints, contains, defaultBase, depth, errorInfo, lightClone, makeCTree, makeGraphvizTree, makeLatexTree, makeLispTree, nodeEquivalentTo, nodeInPosition, numNodes, numNodes, parentType, pathLength, printNode, printNode, printNode, printNodeForHumans, printNodeForHumans, printRootedTree, printRootedTree, printRootedTree, printRootedTreeForHumans, printRootedTreeForHumans, readRootedTree, readRootedTree, replaceWith, rootedTreeEquals, rootedTreeHashCode, rootParent, swapCompatibleWith, toStringForError, writeRootedTree
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IntegerTerminal

public IntegerTerminal()
Method Detail

resetNode

public void resetNode(ec.EvolutionState state,
                      int thread)
Description copied from class: ec.gp.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 ec.gp.ERC

setup

public void setup(ec.EvolutionState state,
                  ec.util.Parameter base)
Description copied from class: ec.gp.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 ec.Prototype
Specified by:
setup in interface ec.Setup
Overrides:
setup in class ec.gp.GPNode

name

public java.lang.String name()
Description copied from class: ec.gp.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 ec.gp.ERC

toString

public java.lang.String toString()
Description copied from class: ec.gp.ERC
This defaults to simply name() + "[" + encode() + "]". You probably shouldn't deviate from this.

Overrides:
toString in class ec.gp.ERC

nodeHashCode

public int nodeHashCode()
Description copied from class: ec.gp.ERC
Implement this to hash ERCs, along with other nodes, in such a way that two "equal" ERCs will usually hash to the same value. The default value, which may not be very good, is a combination of the class hash code and the hash code of the string returned by encode(). You might make a better hash value.

Overrides:
nodeHashCode in class ec.gp.ERC

nodeEquals

public boolean nodeEquals(ec.gp.GPNode node)
Description copied from class: ec.gp.ERC
Implement this to do ERC-to-ERC comparisons.

Specified by:
nodeEquals in class ec.gp.ERC

readNode

public void readNode(ec.EvolutionState state,
                     java.io.DataInput dataInput)
              throws java.io.IOException
Description copied from class: ec.gp.ERC
To successfully read from a DataOutput, you must override this to read your specific ERC data in. The default implementation issues a fatal error.

Overrides:
readNode in class ec.gp.ERC
Throws:
java.io.IOException

writeNode

public void writeNode(ec.EvolutionState state,
                      java.io.DataOutput dataOutput)
               throws java.io.IOException
Description copied from class: ec.gp.ERC
To successfully write to a DataOutput, you must override this to write your specific ERC data out. The default implementation issues a fatal error.

Overrides:
writeNode in class ec.gp.ERC
Throws:
java.io.IOException

encode

public java.lang.String encode()
Description copied from class: ec.gp.ERC
Encodes data from the ERC, using ec.util.Code.

Specified by:
encode in class ec.gp.ERC

decode

public boolean decode(ec.util.DecodeReturn dret)
Description copied from class: ec.gp.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 ec.gp.ERC

checkConstraints

public void checkConstraints(ec.EvolutionState state,
                             int tree,
                             ec.gp.GPIndividual typicalIndividual,
                             ec.util.Parameter individualBase)
Description copied from class: ec.gp.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:
checkConstraints in class ec.gp.ERC

eval

public void eval(ec.EvolutionState state,
                 int thread,
                 ec.gp.GPData input,
                 ec.gp.ADFStack stack,
                 ec.gp.GPIndividual individual,
                 ec.Problem problem)
Description copied from class: ec.gp.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 ec.gp.GPNode

getRandom

public int getRandom(ec.EvolutionState state,
                     int thread)