gap
Class GPFunction

java.lang.Object
  |
  +--gap.GPFunction
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable
Direct Known Subclasses:
GPTerminal

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

This class represents a function in a program tree.

Author:
Pietro Berkes, Samuele Pedroni
See Also:
Serialized Form

Field Summary
 GPFunction[] arg
          Arguments of the function
 Ref father
          Reference to the father.
 int idx
          Index in the function set; set by GPProgram.
static int NO_TYPE
          No information on the type.
static int SPECIAL
          Special type: type information has to be found elsewhere.
 
Constructor Summary
GPFunction()
           
 
Method Summary
 void compile(jrgp.bytecoder0.Bytecoder coder, CompileContext ctxt)
          Do not try (to implement) this at home.
 GPFunction deepClone(GPProgram p, Ref father)
          Clone the function and all his arguments.
abstract  float exec(java.lang.Object o, float[] args)
          Execute the function with reference to an object and an array of arguments.
 int[] getCompatibility(int arg_no)
          Grammatical rules.
 int getNArgs()
          Return the number of arguments.
 java.lang.String getObjArgTypeName()
          Return the name of the object passed to the exec method.
 int getType()
          Return the type of the function, for grammatical purposes.
 java.lang.String prettyPrint(java.lang.String ident)
          Return a string representation of the function and its children.
 java.lang.String toString()
          Return the name of the function, extracted from the class name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

idx

public int idx
Index in the function set; set by GPProgram.

arg

public GPFunction[] arg
Arguments of the function

father

public Ref father
Reference to the father.

NO_TYPE

public static final int NO_TYPE
No information on the type.

SPECIAL

public static final int SPECIAL
Special type: type information has to be found elsewhere. For ADFs and arguments.
Constructor Detail

GPFunction

public GPFunction()
Method Detail

getType

public int getType()
Return the type of the function, for grammatical purposes.

getCompatibility

public int[] getCompatibility(int arg_no)
Grammatical rules. Each argument must accept at least one type of terminal.
Returns:
Array of types accepted from the argument #arg_no, null if all types accepted.

getNArgs

public int getNArgs()
Return the number of arguments.

exec

public abstract float exec(java.lang.Object o,
                           float[] args)
Execute the function with reference to an object and an array of arguments.

toString

public java.lang.String toString()
Return the name of the function, extracted from the class name.
Overrides:
toString in class java.lang.Object

prettyPrint

public java.lang.String prettyPrint(java.lang.String ident)
Return a string representation of the function and its children.

compile

public void compile(jrgp.bytecoder0.Bytecoder coder,
                    CompileContext ctxt)
             throws CompileFailureException
Do not try (to implement) this at home. OTOH fs-d can ;).

Default behaviour is to throw a CompileFailureException about missing compile support.
OTOH fs-d produces GPFunctions with the needed compile logic.


getObjArgTypeName

public java.lang.String getObjArgTypeName()
Return the name of the object passed to the exec method. For compilation purposes.
See Also:
exec(java.lang.Object, float[])

deepClone

public GPFunction deepClone(GPProgram p,
                            Ref father)
Clone the function and all his arguments.