Class gpjpp.GPNodeSet
All Packages Class Hierarchy This Package Previous Next Index
Class gpjpp.GPNodeSet
java.lang.Object
|
+----gpjpp.GPObject
|
+----gpjpp.GPContainer
|
+----gpjpp.GPNodeSet
- public class GPNodeSet
- extends GPContainer
Stores information about the functions and terminals used in
one tree branch of a particular genetic programming problem.
GPNodeSet is a container that holds an arbitrary number of
function and terminal nodes. For improved performance during
some operations, all of the functions are stored at the beginning
of the container and all of the terminals are stored at the end.
There might be some null elements in the middle and the code is
designed to accommodate those.
- Version:
- 1.0
- See Also:
- GPNode, GPAdfNodeSet
-
numFunctions
- The number of function node types supported by this branch.
-
numTerminals
- The number of terminal node types supported by this branch.
-
GPNodeSet()
- Public null constructor used during stream loading only.
-
GPNodeSet(GPNodeSet)
- A constructor that can be called to clone a GPNodeSet.
-
GPNodeSet(int)
- The constructor called by user code to reserve space for
the functions and terminals allowed in this branch.
-
chooseFunction()
- Returns a random function node from this set.
-
chooseNodeWithArgs(int)
- Returns a random node from this set with the specified
number of arguments.
-
chooseTerminal()
- Returns a random terminal node from this set.
-
clone()
- Implements the Cloneable interface.
-
equals(Object)
- Determines whether this GPNodeSet equals another object.
-
functions()
- Returns the number of functions in this node set.
-
isA()
- Returns a code identifying the class in a stream file.
-
load(DataInputStream)
- Loads a GPNodeSet from the specified stream.
-
printOn(PrintStream, GPVariables)
- Writes a GPNodeSet in text format to a PrintStream.
-
putNode(GPNode)
- Adds a function or terminal node to a GPNodeSet.
-
save(DataOutputStream)
- Saves a GPNodeSet to the specified stream.
-
searchForNode(int)
- Returns the GPNode in this set that has the specified node
value, or null if none is found.
-
terminals()
- Returns the number of terminals in this node set.
numFunctions
protected int numFunctions
- The number of function node types supported by this branch.
numTerminals
protected int numTerminals
- The number of terminal node types supported by this branch.
GPNodeSet
public GPNodeSet()
- Public null constructor used during stream loading only.
GPNodeSet
public GPNodeSet(int numOfNodes)
- The constructor called by user code to reserve space for
the functions and terminals allowed in this branch.
- Parameters:
- numOfNodes - the maximum number of functions and terminals
to be specified. This can exceed the actual
number added subsequently by calling putNode
but should generally equal the actual number.
GPNodeSet
public GPNodeSet(GPNodeSet gpo)
- A constructor that can be called to clone a GPNodeSet. Normally
not used.
clone
protected synchronized Object clone()
- Implements the Cloneable interface.
This clones a GPNodeSet but is normally not used.
- Returns:
- the cloned object.
- Overrides:
- clone in class GPContainer
isA
public byte isA()
- Returns a code identifying the class in a stream file.
- Returns:
- the ID code NODESETID.
- Overrides:
- isA in class GPContainer
functions
public int functions()
- Returns the number of functions in this node set.
- See Also:
- numFunctions
terminals
public int terminals()
- Returns the number of terminals in this node set.
- See Also:
- numTerminals
putNode
public void putNode(GPNode gpo)
- Adds a function or terminal node to a GPNodeSet. Functions are
automatically stored at the next available location at the
start of the container, while terminals are added at the end
of the container. Do not call GPContainer.put() to store
nodes in a GPNodeSet since this may corrupt the expected
ordering of the nodes.
- Parameters:
- gpo - a non-null GPNode instance.
- Throws: ArrayStoreException
- if the container is already full.
- Throws: RuntimeException
- if a node with gpo's value is already found in
the GPNodeSet.
equals
public boolean equals(Object obj)
- Determines whether this GPNodeSet equals another object.
It returns true if obj is not null, is an instance of a GPNodeSet
(or a descendant), and contains the same
GPNode values.
This function is called when a checkpoint is loaded by
GPRun,
to determine whether the program and the checkpoint are
consistent.
- Parameters:
- obj - any Java object reference, including null.
- Returns:
- true if this and obj are equivalent.
- Overrides:
- equals in class Object
searchForNode
protected GPNode searchForNode(int value)
- Returns the GPNode in this set that has the specified node
value, or null if none is found. For internal use.
chooseFunction
public GPNode chooseFunction()
- Returns a random function node from this set. Used by
GP.create() and
GPGene.create()
to build new trees.
chooseTerminal
public GPNode chooseTerminal()
- Returns a random terminal node from this set. Used by
GPGene.create()
to build new trees.
chooseNodeWithArgs
public GPNode chooseNodeWithArgs(int args)
- Returns a random node from this set with the specified
number of arguments. Returns null if there is no such
node. Used for
swap mutation.
load
protected synchronized void load(DataInputStream is) throws ClassNotFoundException, IOException, InstantiationException, IllegalAccessException
- Loads a GPNodeSet from the specified stream. Reads the
numFunctions and numTerminals fields from the stream
and then loads the container.
- 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.
- Overrides:
- load in class GPContainer
save
protected void save(DataOutputStream os) throws IOException
- Saves a GPNodeSet to the specified stream. Writes the
numFunctions and numTerminals fields to the stream
and then stores the container.
- Throws: IOException
- if an error occurs while writing the stream.
- Overrides:
- save in class GPContainer
printOn
public void printOn(PrintStream os,
GPVariables cfg)
- Writes a GPNodeSet in text format to a PrintStream.
Each node is printed as its representation string followed
by its number of arguments, if any.
- Overrides:
- printOn in class GPContainer
All Packages Class Hierarchy This Package Previous Next Index