com.groovyj.jgprog
Class Function

java.lang.Object
  |
  +--com.groovyj.jgprog.Function
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Add, ADF, And, Argument, Cosine, Divide, Equals, Exponential, False, GreaterThan, If, LessThan, Loop, Multiply, NaturalLogarithm, Nop, Not, One, Or, Sine, Subtract, True, TwoThings, Variable

public abstract class Function
extends java.lang.Object
implements java.io.Serializable

The base class of all terminals and functions. A generic Function consists of zero or more children Functions and a return type. If a Function has zero children then it is a terminal. If a Function has more than zero children then it is a function.

Copyright (c) 2000 Robert Baruch. This code is released under the GNU General Public License (GPL).

Version:
$Id: Function.java,v 1.1 2000/10/12 15:22:55 groovyjava Exp $
Author:
Robert Baruch (jgprog@sourceforge.net)
See Also:
Serialized Form

Field Summary
protected  int arity
           
protected static Individual individual
          The individual currently being evaluated.
protected  Type returnType
          The return type of this node.
 
Constructor Summary
protected Function(int arity, Type type)
          Create a node with the given arity (i.e.
 
Method Summary
 boolean execute_boolean(Chromosome c, int n)
          Executes this node as a boolean.
 double execute_double(Chromosome c, int n)
          Executes this node as a double.
 float execute_float(Chromosome c, int n)
          Executes this node as a float.
 int execute_int(Chromosome c, int n)
          Executes this node as an integer.
 long execute_long(Chromosome c, int n)
          Executes this node as a long.
 java.lang.Object execute_object(Chromosome c, int n)
          Executes this node as an object.
 void execute_void(Chromosome c, int n)
          Executes this node, returning nothing.
 java.lang.Object execute(Chromosome c, int n)
          Executes this node without knowing its return type.
 int getArity()
          Gets the arity (or number of children) of this node.
abstract  Type getChildType(int i)
          Gets the type of node allowed form the given child number.
abstract  java.lang.String getName()
          Gets the name of this node.
 Type getReturnType()
          Gets the return type of this node
static void setIndividual(Individual individual)
          Sets the individual currently being evaluated.
 void setReturnType(Type type)
          Sets the return type of this node
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

returnType

protected Type returnType
The return type of this node.
Since:
1.0

arity

protected int arity

individual

protected static transient Individual individual
The individual currently being evaluated. This is here for nodes (such as ADF) whose execution depends on the individual. It is automatically set by the World when it evaluates an individual.
Since:
1.0
Constructor Detail

Function

protected Function(int arity,
                   Type type)
Create a node with the given arity (i.e. number of children) and the given type.
Parameters:
arity - the number of children
type - the return type for this node
Since:
1.0
Method Detail

setIndividual

public static void setIndividual(Individual individual)
Sets the individual currently being evaluated.
Parameters:
individual - the individual currently being evaluated
Since:
1.0

getArity

public int getArity()
Gets the arity (or number of children) of this node.
Returns:
the arity of this node
Since:
1.0

getReturnType

public Type getReturnType()
Gets the return type of this node
Returns:
the return type of this node
Since:
1.0

setReturnType

public void setReturnType(Type type)
Sets the return type of this node
Parameters:
type - the type to set the return type to
Since:
1.0

execute_boolean

public boolean execute_boolean(Chromosome c,
                               int n)
Executes this node as a boolean.
Returns:
the boolean return value of this node
Throws:
UnsupportedOperationException - if the type of this node is not boolean
Since:
1.0

execute_void

public void execute_void(Chromosome c,
                         int n)
Executes this node, returning nothing.
Throws:
UnsupportedOperationException - if the type of this node is not void
Since:
1.0

execute_int

public int execute_int(Chromosome c,
                       int n)
Executes this node as an integer.
Returns:
the integer return value of this node
Throws:
UnsupportedOperationException - if the type of this node is not integer
Since:
1.0

execute_long

public long execute_long(Chromosome c,
                         int n)
Executes this node as a long.
Returns:
the long return value of this node
Throws:
UnsupportedOperationException - if the type of this node is not long
Since:
1.0

execute_float

public float execute_float(Chromosome c,
                           int n)
Executes this node as a float.
Returns:
the float return value of this node
Throws:
UnsupportedOperationException - if the type of this node is not float
Since:
1.0

execute_double

public double execute_double(Chromosome c,
                             int n)
Executes this node as a double.
Returns:
the double return value of this node
Throws:
UnsupportedOperationException - if the type of this node is not double
Since:
1.0

execute_object

public java.lang.Object execute_object(Chromosome c,
                                       int n)
Executes this node as an object.
Returns:
the object return value of this node
Throws:
UnsupportedOperationException - if the type of this node is not object
Since:
1.0

execute

public java.lang.Object execute(Chromosome c,
                                int n)
Executes this node without knowing its return type.
Returns:
the Object which wraps the return value of this node, or null if the return type is null or unknown.
Since:
1.0

getName

public abstract java.lang.String getName()
Gets the name of this node. Must be overridden in subclasses.
Returns:
the name of this node.
Since:
1.0

getChildType

public abstract Type getChildType(int i)
Gets the type of node allowed form the given child number. Must be overridden in subclasses.
Parameters:
i - the child number
Returns:
the type of node allowed for that child
Since:
1.0