MOEA Framework 2.12
API Specification

org.moeaframework.util.tree
Class Node

java.lang.Object
  extended by org.moeaframework.util.tree.Node
Direct Known Subclasses:
Abs, Acos, Acosh, Add, And, Asin, Asinh, Atan, Atanh, Call, Ceil, Constant, Cos, Cosh, Define, Divide, Equals, Exp, Floor, For, Get, GreaterThan, GreaterThanOrEqual, IfElse, Lambda, LessThan, LessThanOrEqual, Log, Log10, Max, Min, Modulus, Multiply, NOP, Not, Or, Power, Program, Round, Sequence, Set, Sign, Sin, Sinh, Square, SquareRoot, Subtract, Tan, Tanh, Truncate, While

public abstract class Node
extends Object

A node in an expression tree. Expression trees are strongly typed, meaning nodes have defined return types and argument types. The return type of all nodes must match the argument type from its parent node.


Constructor Summary
Node()
          Constructs a new node.
Node(Class<?> returnType, Class<?>... argumentTypes)
          Constructs a new node with the given return type and argument types.
 
Method Summary
abstract  Node copyNode()
          Returns a copy of this node, but without any children or parents assigned.
 Node copyTree()
          Returns a copy of this node including copies of all its arguments (child nodes).
abstract  Object evaluate(Environment environment)
          Evaluates this node in the context of the specified environment.
 Node getArgument(int index)
          Returns the argument (child node) at the specified index.
 Class<?> getArgumentType(int index)
          Returns the type of the argument (child node) at the specified index.
 int getDepth()
          Returns the depth of this node, which is the number of branches between this node and the root.
 Node getFunctionAt(Class<?> type, int index)
          Returns the function (non-terminal) node at the specified index in the subtree rooted at this node, counting only nodes that match the given return type.
 Node getFunctionAt(int index)
          Returns the function (non-terminal) node at the specified index in the subtree rooted at this node.
 int getMaximumHeight()
          Returns the number of branches between this node and the furthest leaf.
 int getMinimumHeight()
          Returns the number of branches between this node and the nearest leaf.
protected  Node getNodeAt(Class<?> type, boolean includeFunctions, boolean includeTerminals, int index)
          Returns the node at the specified index in the subtree rooted at this node.
 Node getNodeAt(Class<?> type, int index)
          Returns the node at the specified index in the subtree rooted at this node, counting only nodes that match the given return type.
 Node getNodeAt(int index)
          Returns the node at the specified index in the subtree rooted at this node.
 int getNumberOfArguments()
          Returns the number of arguments (child nodes) of this node.
 int getNumberOfFunctions()
          Returns the number of function (non-terminal) nodes contained in the subtree rooted at this node.
 int getNumberOfFunctions(Class<?> type)
          Returns the number of function (non-terminal) nodes contained in the subtree rooted at this node that match the given return type.
 int getNumberOfNodes()
          Returns the number of nodes contained in the subtree rooted at this node.
 int getNumberOfNodes(Class<?> type)
          Returns the number of nodes contained in the subtree rooted at this node that match the given return type.
protected  int getNumberOfNodes(Class<?> type, boolean includeFunctions, boolean includeTerminals)
          Returns the number of nodes contained in the subtree rooted at this node.
 int getNumberOfTerminals()
          Returns the number of terminal nodes contained in the subtree rooted at this node.
 int getNumberOfTerminals(Class<?> type)
          Returns the number of terminal nodes contained in the subtree rooted at this node that match the given return type.
 Node getParent()
          Returns the parent of this node; or null if this node has no parent.
 Class<?> getReturnType()
          Returns the return type of this node.
 Node getTerminalAt(Class<?> type, int index)
          Returns the terminal node at the specified index in the subtree rooted at this node, counting only nodes that match the given return type.
 Node getTerminalAt(int index)
          Returns the terminal node at the specified index in the subtree rooted at this node.
 boolean isFixed()
          Returns true if this node should not be modified, altered, or replaced; false otherwise.
 boolean isTerminal()
          Returns true if this is a terminal node (has no arguments); false otherwise.
 boolean isValid()
          Returns true if this node and its arguments are valid; false otherwise.
 Node setArgument(int index, Node expression)
          Sets the argument (child node) at the specified index.
 void setFixed(boolean fixed)
          Set to true if this node should not be modified, altered, or replaced; false otherwise.
 void setFixedTree(boolean fixed)
          Calls setFixed(boolean) on all nodes in the subtree rooted at this node.
 int size()
          Returns the number of nodes contained in the tree rooted at this node.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Node

public Node()
Constructs a new node.


Node

public Node(Class<?> returnType,
            Class<?>... argumentTypes)
Constructs a new node with the given return type and argument types.

Parameters:
returnType - the return type of the node
argumentTypes - the type of the arguments, if any, for the node
Method Detail

setFixedTree

public void setFixedTree(boolean fixed)
Calls setFixed(boolean) on all nodes in the subtree rooted at this node.

Parameters:
fixed - true if all nodes in the subtree rooted at this node should not be modified, altered, or replaced; false otherwise

setFixed

public void setFixed(boolean fixed)
Set to true if this node should not be modified, altered, or replaced; false otherwise.

Parameters:
fixed - true if this node should not be modified, altered, or replaced; false otherwise

isFixed

public boolean isFixed()
Returns true if this node should not be modified, altered, or replaced; false otherwise.

Returns:
true if this node should not be modified, altered, or replaced; false otherwise

getNumberOfArguments

public int getNumberOfArguments()
Returns the number of arguments (child nodes) of this node.

Returns:
the number of arguments (child nodes) of this node

getArgument

public Node getArgument(int index)
Returns the argument (child node) at the specified index.

Parameters:
index - the index of the argument to return
Returns:
the argument (child node) at the specified index

getParent

public Node getParent()
Returns the parent of this node; or null if this node has no parent.

Returns:
the parent of this node; or null if this node has no parent

getReturnType

public Class<?> getReturnType()
Returns the return type of this node.

Returns:
the return type of this node

getArgumentType

public Class<?> getArgumentType(int index)
Returns the type of the argument (child node) at the specified index.

Parameters:
index - the index of the argument
Returns:
the type of the argument (child node) at the specified index

setArgument

public Node setArgument(int index,
                        Node expression)
Sets the argument (child node) at the specified index.

Parameters:
index - the index of the new argument
expression - the expression defining the argument
Returns:
a reference to this node, allowing multiple calls to be chained together

size

public int size()
Returns the number of nodes contained in the tree rooted at this node.

Returns:
the number of nodes contained in the tree rooted at this node

getDepth

public int getDepth()
Returns the depth of this node, which is the number of branches between this node and the root.

Returns:
the depth of this node

getMinimumHeight

public int getMinimumHeight()
Returns the number of branches between this node and the nearest leaf.

Returns:
the number of branches between this node and the nearest leaf

getMaximumHeight

public int getMaximumHeight()
Returns the number of branches between this node and the furthest leaf.

Returns:
the number of branches between this node and the furthest leaf

copyNode

public abstract Node copyNode()
Returns a copy of this node, but without any children or parents assigned.

Returns:
a copy of this node, but without any children or parents assigned

copyTree

public Node copyTree()
Returns a copy of this node including copies of all its arguments (child nodes). All attributes of the node are also retained, such as isFixed().

Returns:
a copy of this node including copies of all its arguments (child nodes)

evaluate

public abstract Object evaluate(Environment environment)
Evaluates this node in the context of the specified environment.

Parameters:
environment - the execution environment
Returns:
the result of evaluating this node

isValid

public boolean isValid()
Returns true if this node and its arguments are valid; false otherwise. A valid node has all arguments defined, all arguments are valid, and all arguments are the appropriate type.

Returns:
true if this node and its arguments are valid; false otherwise

toString

public String toString()
Overrides:
toString in class Object

isTerminal

public boolean isTerminal()
Returns true if this is a terminal node (has no arguments); false otherwise.

Returns:
true if this is a terminal node (has no arguments); false otherwise

getNumberOfFunctions

public int getNumberOfFunctions(Class<?> type)
Returns the number of function (non-terminal) nodes contained in the subtree rooted at this node that match the given return type.

Parameters:
type - the return type of the node
Returns:
the number of function (non-terminal) nodes contained in the subtree rooted at this node that match the given return type

getFunctionAt

public Node getFunctionAt(Class<?> type,
                          int index)
Returns the function (non-terminal) node at the specified index in the subtree rooted at this node, counting only nodes that match the given return type. A depth-first search (DFS) walk of the tree is used to find the appropriate node.

Parameters:
type - the return type of the node
index - the index of the node to return
Returns:
the function (non-terminal) node at the specified index in the subtree rooted at this node, counting only nodes that match the given return type
Throws:
IndexOutOfBoundsException - if the index refers to a node not within the subtree rooted at this node

getNumberOfFunctions

public int getNumberOfFunctions()
Returns the number of function (non-terminal) nodes contained in the subtree rooted at this node.

Returns:
the number of function (non-terminal) nodes contained in the subtree rooted at this node

getFunctionAt

public Node getFunctionAt(int index)
Returns the function (non-terminal) node at the specified index in the subtree rooted at this node. A depth-first search (DFS) walk of the tree is used to find the appropriate node.

Parameters:
index - the index of the node to return
Returns:
the function (non-terminal) node at the specified index in the subtree rooted at this node
Throws:
IndexOutOfBoundsException - if the index refers to a node not within the subtree rooted at this node

getNumberOfTerminals

public int getNumberOfTerminals(Class<?> type)
Returns the number of terminal nodes contained in the subtree rooted at this node that match the given return type.

Parameters:
type - the return type of the node
Returns:
the number of terminal nodes contained in the subtree rooted at this node that match the given return type

getTerminalAt

public Node getTerminalAt(Class<?> type,
                          int index)
Returns the terminal node at the specified index in the subtree rooted at this node, counting only nodes that match the given return type. A depth-first search (DFS) walk of the tree is used to find the appropriate node.

Parameters:
type - the return type of the node
index - the index of the node to return
Returns:
the terminal node at the specified index in the subtree rooted at this node, counting only nodes that match the given return type
Throws:
IndexOutOfBoundsException - if the index refers to a node not within the subtree rooted at this node

getNumberOfTerminals

public int getNumberOfTerminals()
Returns the number of terminal nodes contained in the subtree rooted at this node.

Returns:
the number of terminal nodes contained in the subtree rooted at this node

getTerminalAt

public Node getTerminalAt(int index)
Returns the terminal node at the specified index in the subtree rooted at this node. A depth-first search (DFS) walk of the tree is used to find the appropriate node.

Parameters:
index - the index of the node to return
Returns:
the terminal node at the specified index in the subtree rooted at this node
Throws:
IndexOutOfBoundsException - if the index refers to a node not within the subtree rooted at this node

getNumberOfNodes

public int getNumberOfNodes(Class<?> type)
Returns the number of nodes contained in the subtree rooted at this node that match the given return type.

Parameters:
type - the return type of the node
Returns:
the number of nodes contained in the subtree rooted at this node that match the given return type

getNodeAt

public Node getNodeAt(Class<?> type,
                      int index)
Returns the node at the specified index in the subtree rooted at this node, counting only nodes that match the given return type. A depth-first search (DFS) walk of the tree is used to find the appropriate node.

Parameters:
type - the return type of the node
index - the index of the node to return
Returns:
the node at the specified index in the subtree rooted at this node, counting only nodes that match the given return type
Throws:
IndexOutOfBoundsException - if the index refers to a node not within the subtree rooted at this node

getNumberOfNodes

public int getNumberOfNodes()
Returns the number of nodes contained in the subtree rooted at this node.

Returns:
the number of nodes contained in the subtree rooted at this node

getNodeAt

public Node getNodeAt(int index)
Returns the node at the specified index in the subtree rooted at this node. A depth-first search (DFS) walk of the tree is used to find the appropriate node.

Parameters:
index - the index of the node to return
Returns:
the node at the specified index in the subtree rooted at this node
Throws:
IndexOutOfBoundsException - if the index refers to a node not within the subtree rooted at this node

getNumberOfNodes

protected int getNumberOfNodes(Class<?> type,
                               boolean includeFunctions,
                               boolean includeTerminals)
Returns the number of nodes contained in the subtree rooted at this node.

Parameters:
type - the return type of the node
includeFunctions - true if functions (non-terminals) are counted; false otherwise
includeTerminals - true if terminals are counted; false otherwise
Returns:
the number of nodes contained in the subtree rooted at this node

getNodeAt

protected Node getNodeAt(Class<?> type,
                         boolean includeFunctions,
                         boolean includeTerminals,
                         int index)
Returns the node at the specified index in the subtree rooted at this node. A depth-first search (DFS) walk of the tree is used to find the appropriate node.

Parameters:
type - the return type of the node
includeFunctions - true if functions (non-terminals) are counted; false otherwise
includeTerminals - true if terminals are counted; false otherwise
index - the index of the node to return
Returns:
the node at the specified index in the subtree rooted at this node
Throws:
IndexOutOfBoundsException - if the index refers to a node not within the subtree rooted at this node

MOEA Framework 2.12
API Specification

Copyright 2009-2016 MOEA Framework. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage. Visit us on Github!