Class gpjpp.GPObject
All Packages Class Hierarchy This Package Previous Next Index
Class gpjpp.GPObject
java.lang.Object
|
+----gpjpp.GPObject
- public class GPObject
- extends Object
- implements Cloneable
Abstract class used to define cloning and streaming capabilities.
All gpjpp classes that can be streamed are subclasses of GPObject.
- Version:
- 1.0
-
ADFNODESETID
- An ID code used to identify
GPAdfNodeSet
references in gpjpp streams.
-
CONTAINERID
- An ID code used to identify
GPContainer
references in gpjpp streams.
-
GENEID
- An ID code used to identify
GPGene references in
gpjpp streams.
-
GENEPRINTID
- An ID code used to identify
GPGenePrint
references in gpjpp streams.
-
GPID
- An ID code used to identify
GP references in
gpjpp streams.
-
NODEID
- An ID code used to identify
GPNode references in
gpjpp streams.
-
NODESETID
- An ID code used to identify
GPNodeSet references in
gpjpp streams.
-
NULLID
- An ID code used to identify null object references in
gpjpp streams.
-
OBJECTID
- An ID code used to identify GPObject references in
gpjpp streams.
-
POPULATIONID
- An ID code used to identify
GPPopulation
references in gpjpp streams.
-
USERGENEID
- An ID code normally used to identify the user subclass of
GPGene.
-
USERGPID
- An ID code normally used to identify the user subclass of
GP.
-
USERPOPULATIONID
- An ID code normally used to identify the user subclass of
GPPopulation.
-
USERVARIABLESID
- An ID code normally used to identify the user subclass of
GPVariables.
-
VARIABLESID
- An ID code used to identify
GPVariables
references in gpjpp streams.
-
GPObject()
- This do-nothing constructor gets called implicitly by
subclasses of GPObject.
-
clone()
- Implements the Cloneable interface.
-
createRegisteredClassObject(byte)
- Creates an object of specified ID and returns it.
-
findRegisteredClass(byte)
- Returns index of existing registered class, -1 if not found.
-
isA()
- Returns a code identifying the class in a stream file.
-
load(DataInputStream)
- Loads a GPObject subclass from the specified stream.
-
printOn(PrintStream, GPVariables)
- Writes a GPObject subclass in text format to a PrintStream.
-
registerClass(byte, Class)
- Registers a single class.
-
registerClass(GPObject)
- Registers the class of the specified object and
all of its non-abstract superclasses up to but
not including GPObject.
-
save(DataOutputStream)
- Saves a GPObject subclass to the specified stream.
NULLID
protected final static byte NULLID
- An ID code used to identify null object references in
gpjpp streams.
OBJECTID
protected final static byte OBJECTID
- An ID code used to identify GPObject references in
gpjpp streams. This code is not written to streams
under normal circumstances, since GPObject is an
abstract class.
CONTAINERID
protected final static byte CONTAINERID
- An ID code used to identify
GPContainer
references in gpjpp streams. This code is not written to streams
under normal circumstances, since GPContainer subclasses
provide their own ID codes.
NODEID
protected final static byte NODEID
- An ID code used to identify
GPNode references in
gpjpp streams. A GPNode defines the identifying code,
number of arguments, and string representation for
every function and terminal in a genetic program.
NODESETID
protected final static byte NODESETID
- An ID code used to identify
GPNodeSet references in
gpjpp streams. A GPNodeSet contains all the GPNode
values for a particular branch (main result-producing
or ADF) of a genetic program.
ADFNODESETID
protected final static byte ADFNODESETID
- An ID code used to identify
GPAdfNodeSet
references in gpjpp streams. A GPAdfNodeSet contains all the
GPNodeSet containers for a genetic program.
VARIABLESID
protected final static byte VARIABLESID
- An ID code used to identify
GPVariables
references in gpjpp streams. A GPVariables contains all the
settings that specify the behavior of a genetic programming test.
A user subclass of GPVariables is often, but not always,
defined to specify additional problem-specific variables.
GENEID
protected final static byte GENEID
- An ID code used to identify
GPGene references in
gpjpp streams. A GPGene is one node of a genetic program
parse tree and includes a reference to a
GPNode and
a container holding references to the arguments of the
node, if any. This ID code may appear hundreds of thousands
of times in a stream. A user subclass of GPGene is almost
always defined to implement a problem-specific fitness
calculation for each gene tree.
GPID
protected final static byte GPID
- An ID code used to identify
GP references in
gpjpp streams. GP is a container holding references to
a GPGene for each branch
of the genetic program, including one for the main
result-producing branch and zero or more
for the ADFs of the program. There is a GP for each member
of the population. A user subclass of GP is always defined
to implement a problem-specific fitness calculation for each
genetic program.
POPULATIONID
protected final static byte POPULATIONID
- An ID code used to identify
GPPopulation
references in gpjpp streams. GPPopulation is a container holding
references to a GP for each individual in the population.
A user subclass of GPPopulation is always defined to create GP
subclass instances when the program needs them.
GENEPRINTID
protected final static byte GENEPRINTID
- An ID code used to identify
GPGenePrint
references in gpjpp streams. This code is not written to streams
under normal circumstances, and the GPGenePrint load and save
methods do nothing.
USERGENEID
public final static byte USERGENEID
- An ID code normally used to identify the user subclass of
GPGene.
USERGPID
public final static byte USERGPID
- An ID code normally used to identify the user subclass of
GP.
USERPOPULATIONID
public final static byte USERPOPULATIONID
- An ID code normally used to identify the user subclass of
GPPopulation.
USERVARIABLESID
public final static byte USERVARIABLESID
- An ID code normally used to identify the user subclass of
GPVariables. For any stream classes besides those
discussed here, use ID codes larger than USERVARIABLESID.
GPObject
protected GPObject()
- This do-nothing constructor gets called implicitly by
subclasses of GPObject.
clone
protected synchronized abstract Object clone()
- Implements the Cloneable interface.
GPGene and GP classes are cloned during reproduction
and crossover.
- Returns:
- the cloned object.
- Overrides:
- clone in class Object
isA
public abstract byte isA()
- Returns a code identifying the class in a stream file.
Every class in a streamed gpjpp program must override
isA() and return a unique byte. Predefined ID values are
provided for the built-in gpjpp classes and the classes
a user is expected to provide.
- Returns:
- the unique ID code.
- See Also:
- OBJECTID
load
protected synchronized abstract void load(DataInputStream is) throws ClassNotFoundException, IOException, InstantiationException, IllegalAccessException
- Loads a GPObject subclass from the specified stream. The
object calling this method should have been previously
constructed using its null constructor.
- Parameters:
- is - a formatted input stream.
- Throws: ClassNotFoundException
- if the class indicated by the stream's ID code
is not registered with GPObject.
- Throws: InstantiationException
- if an error occurs while calling new or the null
constructor of the specified class.
- Throws: IllegalAccessException
- if the specified class or its null constructor is
not public.
- Throws: IOException
- if an error occurs while reading the stream.
save
protected abstract void save(DataOutputStream os) throws IOException
- Saves a GPObject subclass to the specified stream.
- Parameters:
- os - a formatted output stream.
- Throws: IOException
- if an error occurs while writing the stream.
printOn
public abstract void printOn(PrintStream os,
GPVariables cfg)
- Writes a GPObject subclass in text format to a PrintStream.
Every gpjpp subclass overrides this method to print a text
representation of the class' current state.
Because printOn writes to a PrintStream, it does not generate
IOExceptions. PrintStream traps exceptions, which can be
checked via its checkError() method.
- Parameters:
- os - a PrintStream.
- cfg - the set of gpjpp configuration variables,
sometimes used to control the output.
findRegisteredClass
protected static int findRegisteredClass(byte id)
- Returns index of existing registered class, -1 if not found.
For internal use.
createRegisteredClassObject
public static GPObject createRegisteredClassObject(byte id) throws InstantiationException, IllegalAccessException
- Creates an object of specified ID and returns it.
This method is called by appropriate load() methods in the
gpjpp class hierarchy.
- Parameters:
- id - the registered ID code for the class type to create.
- Returns:
- an object of the specified type, created via its
null constructor. Returns null if the ID code does
not specify a registered type.
- Throws: InstantiationException
- if an error occurs while calling new or the null
constructor of the specified class.
- Throws: IllegalAccessException
- if the specified class or its null constructor is
not public.
registerClass
protected static void registerClass(byte id,
Class c)
- Registers a single class. For internal use.
registerClass
public static void registerClass(GPObject gpo) throws IllegalAccessException
- Registers the class of the specified object and
all of its non-abstract superclasses up to but
not including GPObject.
- Parameters:
- gpo - an instance of the class to register
- Throws: IllegalAccessException
- if a superclass of the specified class or
its null constructor is not public.
All Packages Class Hierarchy This Package Previous Next Index