classifier.gp
Class GProgram

java.lang.Object
  extended byclassifier.gp.GProgram
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable
Direct Known Subclasses:
Function, Terminal

public abstract class GProgram
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

Abstract class that stands over the 2 kind of possible nodes and their real implementation; moreover it brings some common methods to operate over trees

Version:
0.1
Author:
Sacchi Matteo, Sassi Federico
See Also:
Serialized Form

Constructor Summary
GProgram()
           
 
Method Summary
protected abstract  java.lang.Object clone()
          clone the current object
(package private) abstract  int countNodes()
          count all the nodes under this object
(package private) abstract  int countNodes(Condition cond)
          count the nodes of the desidered kind
abstract  char[] eval(char[] string)
           
abstract  double eval(double i)
           
abstract  long eval(long x)
           
abstract  java.lang.Object eval(java.lang.Object x)
          Evaluate the program under the node passing an object
abstract  java.lang.String getName()
          To get the name of the function of the node or the type of the terminal
protected static Joint getSubtree(GProgram tree, int index, Condition cond)
          To have the Joint structure containg the information to break the tree in the desidered point
 java.lang.String indent(int level)
          utility function to make a correct indentation
protected static int maxDepthOfTree(GProgram tree)
          To know the maximum depth of a tree
abstract  java.lang.String toString(int level)
          Prints the content of the tree from the level indicated
protected static TreeJoint Walk(GProgram tree, int[] count, Condition cond, Function parent, int childIndex)
          Method to explore the tree looking for the desidered subtree
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GProgram

public GProgram()
Method Detail

toString

public abstract java.lang.String toString(int level)
Prints the content of the tree from the level indicated

Parameters:
level - the level of the tree from which to start
Returns:
a string containg the content of the tree

getName

public abstract java.lang.String getName()
To get the name of the function of the node or the type of the terminal

Returns:
a name like "and" or "constant"....

eval

public abstract java.lang.Object eval(java.lang.Object x)
Evaluate the program under the node passing an object

Parameters:
x - the object to evaluale (eg. classify)
Returns:
the result of the evaluation as an object

eval

public abstract long eval(long x)

eval

public abstract double eval(double i)

eval

public abstract char[] eval(char[] string)

countNodes

abstract int countNodes()
count all the nodes under this object

Returns:
the number of the nodes

countNodes

abstract int countNodes(Condition cond)
count the nodes of the desidered kind

Parameters:
cond - the desidered kind of nodes to be counted (eg. function or terminal)
Returns:
the number of the nodes

clone

protected abstract java.lang.Object clone()
clone the current object

Returns:
cloned object

indent

public java.lang.String indent(int level)
utility function to make a correct indentation

Parameters:
level - how many level to indent
Returns:
a string with the correct number of spaces

getSubtree

protected static Joint getSubtree(GProgram tree,
                                  int index,
                                  Condition cond)
To have the Joint structure containg the information to break the tree in the desidered point

Parameters:
tree - the program to break
index - the number of the node where to break
cond - the kind of node to break (eg. function or terminal)
Returns:
structure containg the information to break the tree in the desidered point

Walk

protected static TreeJoint Walk(GProgram tree,
                                int[] count,
                                Condition cond,
                                Function parent,
                                int childIndex)
Method to explore the tree looking for the desidered subtree

Parameters:
tree - the program to break
count - the number of the node where to break
cond - the kind of node to break (eg. function or terminal)
parent - to set the parent attribute in the TreeJoint structure
childIndex - to set the childIndex attribute in the TreeJoint structure
Returns:
structure containg the information to break the tree in the desidered point
See Also:
TreeJoint

maxDepthOfTree

protected static int maxDepthOfTree(GProgram tree)
To know the maximum depth of a tree

Parameters:
tree - the tree to analize
Returns:
integer correspondig to the maximum depth of the selected tree