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

Variable Index

 o numFunctions
The number of function node types supported by this branch.
 o numTerminals
The number of terminal node types supported by this branch.

Constructor Index

 o GPNodeSet()
Public null constructor used during stream loading only.
 o GPNodeSet(GPNodeSet)
A constructor that can be called to clone a GPNodeSet.
 o GPNodeSet(int)
The constructor called by user code to reserve space for the functions and terminals allowed in this branch.

Method Index

 o chooseFunction()
Returns a random function node from this set.
 o chooseNodeWithArgs(int)
Returns a random node from this set with the specified number of arguments.
 o chooseTerminal()
Returns a random terminal node from this set.
 o clone()
Implements the Cloneable interface.
 o equals(Object)
Determines whether this GPNodeSet equals another object.
 o functions()
Returns the number of functions in this node set.
 o isA()
Returns a code identifying the class in a stream file.
 o load(DataInputStream)
Loads a GPNodeSet from the specified stream.
 o printOn(PrintStream, GPVariables)
Writes a GPNodeSet in text format to a PrintStream.
 o putNode(GPNode)
Adds a function or terminal node to a GPNodeSet.
 o save(DataOutputStream)
Saves a GPNodeSet to the specified stream.
 o searchForNode(int)
Returns the GPNode in this set that has the specified node value, or null if none is found.
 o terminals()
Returns the number of terminals in this node set.

Variables

 o numFunctions
  protected int numFunctions
The number of function node types supported by this branch.
 o numTerminals
  protected int numTerminals
The number of terminal node types supported by this branch.

Constructors

 o GPNodeSet
  public GPNodeSet()
Public null constructor used during stream loading only.
 o 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.
 o GPNodeSet
  public GPNodeSet(GPNodeSet gpo)
A constructor that can be called to clone a GPNodeSet. Normally not used.

Methods

 o 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
 o isA
  public byte isA()
Returns a code identifying the class in a stream file.
Returns:
the ID code NODESETID.
Overrides:
isA in class GPContainer
 o functions
  public int functions()
Returns the number of functions in this node set.
See Also:
numFunctions
 o terminals
  public int terminals()
Returns the number of terminals in this node set.
See Also:
numTerminals
 o 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.
 o 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
 o 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.
 o chooseFunction
  public GPNode chooseFunction()
Returns a random function node from this set. Used by GP.create() and GPGene.create() to build new trees.
 o chooseTerminal
  public GPNode chooseTerminal()
Returns a random terminal node from this set. Used by GPGene.create() to build new trees.
 o 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.
 o 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
 o 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
 o 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