ac.essex.ooechs.ecj.ecj2java.nodes
Class ParseableERC

java.lang.Object
  extended by ec.gp.GPNode
      extended by ec.gp.ERC
          extended by ac.essex.ooechs.ecj.ecj2java.nodes.ParseableERC
All Implemented Interfaces:
ParseableNode, ec.gp.GPNodeParent, ec.Prototype, ec.Setup, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
Number

public abstract class ParseableERC
extends ec.gp.ERC
implements ParseableNode

ParseableERC is an adapter class that serves two functions:

  1. It allows ECJ2Java to write the ERC into pure java
  2. It makes ERCs easier to code

It adapts a number of unpleasant methods in the ERC class that don't need to be altered often (if at all).

It implements the functionality required by ParseableNode which allows the node to be converted into pure java.

Implementation is easy - just take your existing ERC and extend ParseableERC instead of ERC. The only required methods are setNumber() and name().

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version, provided that any use properly credits the author. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details at http://www.gnu.org

Version:
1.0
Author:
Olly Oechsle, University of Essex, Date: 06-Sep-2006
See Also:
Serialized Form

Field Summary
protected  int type
           
protected  double value
           
(package private)  java.lang.String variableName
           
 
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
 
Fields inherited from interface ac.essex.ooechs.ecj.ecj2java.nodes.ParseableNode
BOOLEAN, DOUBLE, ERC, FUNCTION, INT, RETURN, VOID
 
Constructor Summary
ParseableERC()
           
 
Method Summary
 int countChildren()
          Returns how many children this node has
 boolean decode(ec.util.DecodeReturn dret)
           
 java.lang.String encode()
           
 void eval(ec.EvolutionState state, int thread, ec.gp.GPData input, ec.gp.ADFStack stack, ec.gp.GPIndividual individual, ec.Problem problem)
           
 ParseableNode getChild(int index)
          Gets the child of this node at a given index.
 java.lang.String getJavaCode()
          Writes out the java for this node
 java.lang.String getLineComment()
          There may be a line comment associated with this piece of code.
 int getType()
          Returns what kind of node this is.
 java.lang.String getValue()
           
 java.lang.String getVariableName()
          When the java writer uses this node, it may use a variable name to describe it.
 void mutateERC(ec.EvolutionState state, int thread)
          Mutates the node's "value".
abstract  java.lang.String name()
          The name of the class that ECK uses.
 boolean nodeEquals(ec.gp.GPNode node)
           
 int nodeHashCode()
           
 void readNode(ec.EvolutionState state, java.io.DataInput dataInput)
           
 void resetNode(ec.EvolutionState state, int thread)
           
abstract  double setNumber(ec.EvolutionState state, int thread)
          Set the value of the ERC here
 void setType(int type)
          Set the node type
 void setValue(double value)
           
 void setVariableName(java.lang.String name)
          Attaches a variable name to this node, used by JavaWriter
 java.lang.String toStringForHumans()
           
 void writeNode(ec.EvolutionState state, java.io.DataOutput dataOutput)
           
 
Methods inherited from class ec.gp.ERC
checkConstraints, readNode, toString
 
Methods inherited from class ec.gp.GPNode
atDepth, cloneReplacing, cloneReplacing, cloneReplacing, cloneReplacingAtomic, cloneReplacingAtomic, cloneReplacingAtomicSimple, cloneReplacingAtomicSimple, cloneReplacingNoSubclone, cloneReplacingNoSubcloneSimple, cloneReplacingSimple, cloneReplacingSimple, cloneReplacingSimple, constraints, contains, defaultBase, depth, errorInfo, makeCTree, makeLatexTree, nodeEquivalentTo, nodeInPosition, numNodes, numNodes, parentType, printNode, printNode, printNodeForHumans, printRootedTree, printRootedTree, printRootedTreeForHumans, protoClone, protoCloneSimple, readRootedTree, readRootedTree, replaceWith, rootedTreeEquals, rootedTreeHashCode, rootParent, setup, swapCompatibleWith, toStringForError, writeRootedTree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ac.essex.ooechs.ecj.ecj2java.nodes.ParseableNode
getObjectType
 

Field Detail

type

protected int type

value

protected double value

variableName

java.lang.String variableName
Constructor Detail

ParseableERC

public ParseableERC()
Method Detail

setNumber

public abstract double setNumber(ec.EvolutionState state,
                                 int thread)
Set the value of the ERC here


mutateERC

public void mutateERC(ec.EvolutionState state,
                      int thread)
Mutates the node's "value". This is called by mutating operators which specifically mutate the "value" of ERCs, as opposed to replacing them with whole new ERCs. The default form of this function simply calls resetNode(state,thread), but you might want to modify this to do a specialized form of mutation, applying gaussian noise for example.

Overrides:
mutateERC in class ec.gp.ERC

name

public abstract java.lang.String name()
The name of the class that ECK uses.

Specified by:
name in class ec.gp.ERC

getChild

public ParseableNode getChild(int index)
Description copied from interface: ParseableNode
Gets the child of this node at a given index.

Specified by:
getChild in interface ParseableNode

getType

public int getType()
Description copied from interface: ParseableNode
Returns what kind of node this is.

Specified by:
getType in interface ParseableNode

getValue

public java.lang.String getValue()

setValue

public void setValue(double value)

countChildren

public int countChildren()
Description copied from interface: ParseableNode
Returns how many children this node has

Specified by:
countChildren in interface ParseableNode

getVariableName

public java.lang.String getVariableName()
When the java writer uses this node, it may use a variable name to describe it.

Specified by:
getVariableName in interface ParseableNode

setVariableName

public void setVariableName(java.lang.String name)
Attaches a variable name to this node, used by JavaWriter

Specified by:
setVariableName in interface ParseableNode

getJavaCode

public java.lang.String getJavaCode()
Description copied from interface: ParseableNode
Writes out the java for this node

Specified by:
getJavaCode in interface ParseableNode

getLineComment

public java.lang.String getLineComment()
Description copied from interface: ParseableNode
There may be a line comment associated with this piece of code.

Specified by:
getLineComment in interface ParseableNode

setType

public void setType(int type)
Description copied from interface: ParseableNode
Set the node type

Specified by:
setType in interface ParseableNode

resetNode

public void resetNode(ec.EvolutionState state,
                      int thread)
Specified by:
resetNode in class ec.gp.ERC

nodeEquals

public boolean nodeEquals(ec.gp.GPNode node)
Specified by:
nodeEquals in class ec.gp.ERC

readNode

public void readNode(ec.EvolutionState state,
                     java.io.DataInput dataInput)
              throws java.io.IOException
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
Overrides:
writeNode in class ec.gp.ERC
Throws:
java.io.IOException

encode

public java.lang.String encode()
Specified by:
encode in class ec.gp.ERC

decode

public boolean decode(ec.util.DecodeReturn dret)
Specified by:
decode in class ec.gp.ERC

toStringForHumans

public java.lang.String toStringForHumans()
Overrides:
toStringForHumans 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)
Specified by:
eval in class ec.gp.GPNode

nodeHashCode

public int nodeHashCode()
Specified by:
nodeHashCode in class ec.gp.ERC