ec.app.regression.func
Class RegERC

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

public class RegERC
extends ERC

Version:
1.0
Author:
Sean Luke
See Also:
Serialized Form

Field Summary
 double value
           
 
Fields inherited from class ec.gp.ERC
ERC_PREFIX
 
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, REPLACEMENT_CHAR, SITUATION_MUTATION, SITUATION_NEWIND
 
Constructor Summary
RegERC()
           
 
Method Summary
 boolean decode(DecodeReturn dret)
          Decodes data into the ERC from dret.
 java.lang.String encode()
          Encodes data from the ERC, using ec.util.Code.
 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.
 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(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(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(EvolutionState state, int thread)
          Remember to override this to randomize your ERC after it has been cloned.
 java.lang.String toStringForHumans()
          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.
 void writeNode(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
checkConstraints, mutateERC, readNode, toString
 
Methods inherited from class ec.gp.GPNode
atDepth, clone, cloneReplacing, cloneReplacing, cloneReplacing, cloneReplacingAtomic, cloneReplacingAtomic, cloneReplacingNoSubclone, constraints, contains, defaultBase, depth, errorInfo, lightClone, makeCTree, makeLatexTree, nodeEquivalentTo, nodeInPosition, numNodes, numNodes, parentType, printNode, printNode, printNodeForHumans, printRootedTree, printRootedTree, printRootedTreeForHumans, readRootedTree, readRootedTree, replaceWith, rootedTreeEquals, rootedTreeHashCode, rootParent, setup, swapCompatibleWith, toStringForError, writeRootedTree
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

value

public double value
Constructor Detail

RegERC

public RegERC()
Method Detail

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

nodeHashCode

public int nodeHashCode()
Description copied from class: 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.

Specified by:
nodeHashCode in class ERC

nodeEquals

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

Specified by:
nodeEquals in class ERC

readNode

public void readNode(EvolutionState state,
                     java.io.DataInput dataInput)
              throws java.io.IOException
Description copied from class: 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 ERC
Throws:
java.io.IOException

writeNode

public void writeNode(EvolutionState state,
                      java.io.DataOutput dataOutput)
               throws java.io.IOException
Description copied from class: 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 ERC
Throws:
java.io.IOException

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.

Specified by:
decode in class ERC

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 only one ERC function class, you can just return "". Whatever the name is, it should generally only have letters, numbers, or hyphens or underscores in it. No whitespace or other characters.

Specified by:
name 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 ERC_PREFIX + name() + [ + ... + ]

Overrides:
toStringForHumans 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