fuzzylite  6.0
A Fuzzy Logic Control Library in C++
fl::Function::Node Struct Reference

The Node class structures a binary tree by storing pointers to a left Node and a right Node, and storing its content as a Function::Element, the name of an InputVariable or OutputVariable, or a constant value. More...

#include <Function.h>

Collaboration diagram for fl::Function::Node:

Public Member Functions

 Node (Element *element, Node *left=fl::null, Node *right=fl::null)
 
 Node (const std::string &variable)
 
 Node (scalar value)
 
 Node (const Node &source)
 
Nodeoperator= (const Node &rhs)
 
virtual ~Node ()
 
virtual scalar evaluate (const std::map< std::string, scalar > *variables=fl::null) const
 Evaluates the node and substitutes the variables therein for the values passed in the map. More...
 
virtual std::size_t treeSize (const Node *node=fl::null) const
 Computes the size of the subtree under the given node. More...
 
virtual std::size_t treeSize (Element::Type type, const Node *node=fl::null) const
 Computes the size of the subtree under the given node whose elements are of the given type. More...
 
virtual Nodeclone () const
 Creates a clone of the node. More...
 
virtual std::string toString () const
 Returns a string with the name of the element, the name of the variable, or the constant value, accordingly. More...
 
virtual std::string toPrefix (const Node *node=fl::null) const
 Returns a prefix representation of the expression tree under the given node. More...
 
virtual std::string toInfix (const Node *node=fl::null) const
 Returns an infix representation of the expression tree under the given node. More...
 
virtual std::string toPostfix (const Node *node=fl::null) const
 Returns a postfix representation of the expression tree under the given node. More...
 

Public Attributes

FL_unique_ptr< Elementelement
 The node takes an operation or a function. More...
 
FL_unique_ptr< Nodeleft
 The node can have an expression tree on the left. More...
 
FL_unique_ptr< Noderight
 The node can have an expression tree on the right. More...
 
std::string variable
 The node can refer to a variable by name. More...
 
scalar value
 The node can take an arbitrary floating-point value. More...
 

Detailed Description

The Node class structures a binary tree by storing pointers to a left Node and a right Node, and storing its content as a Function::Element, the name of an InputVariable or OutputVariable, or a constant value.

Definition at line 139 of file Function.h.

Constructor & Destructor Documentation

◆ Node() [1/4]

fl::Function::Node::Node ( Element element,
Node left = fl::null,
Node right = fl::null 
)
explicit

◆ Node() [2/4]

fl::Function::Node::Node ( const std::string &  variable)
explicit

◆ Node() [3/4]

fl::Function::Node::Node ( scalar  value)
explicit

◆ Node() [4/4]

fl::Function::Node::Node ( const Node source)

◆ ~Node()

virtual fl::Function::Node::~Node ( )
virtual

Member Function Documentation

◆ clone()

virtual Node* fl::Function::Node::clone ( ) const
virtual

Creates a clone of the node.

Returns
a clone of the node

◆ evaluate()

virtual scalar fl::Function::Node::evaluate ( const std::map< std::string, scalar > *  variables = fl::null) const
virtual

Evaluates the node and substitutes the variables therein for the values passed in the map.

The expression tree is evaluated recursively.

Parameters
variablesis a map of substitutions of variable names for fl::scalars
Returns
a fl::scalar indicating the result of the evaluation of the node

◆ operator=()

Node& fl::Function::Node::operator= ( const Node rhs)

◆ toInfix()

virtual std::string fl::Function::Node::toInfix ( const Node node = fl::null) const
virtual

Returns an infix representation of the expression tree under the given node.

Parameters
nodeis the node to start the infix representation from. If the node is fl::null, then the starting point is this node
Returns
an infix representation of the expression tree under the given node

◆ toPostfix()

virtual std::string fl::Function::Node::toPostfix ( const Node node = fl::null) const
virtual

Returns a postfix representation of the expression tree under the given node.

Parameters
nodeis the node to start the postfix representation from. If the node is fl::null, then the starting point is this node
Returns
a postfix representation of the expression tree under the given node

◆ toPrefix()

virtual std::string fl::Function::Node::toPrefix ( const Node node = fl::null) const
virtual

Returns a prefix representation of the expression tree under the given node.

Parameters
nodeis the node to start the prefix representation from. If the node is fl::null, then the starting point is this node
Returns
a prefix representation of the expression tree under the given node

◆ toString()

virtual std::string fl::Function::Node::toString ( ) const
virtual

Returns a string with the name of the element, the name of the variable, or the constant value, accordingly.

Returns
a string with the name of the element, the name of the variable, or the constant value, accordingly.

◆ treeSize() [1/2]

virtual std::size_t fl::Function::Node::treeSize ( const Node node = fl::null) const
virtual

Computes the size of the subtree under the given node.

The complexity of calling this method is O(n).

Parameters
nodeis the root of the subtree, which is this node if fl::null is given
Returns
the size of the subtree under the given node

◆ treeSize() [2/2]

virtual std::size_t fl::Function::Node::treeSize ( Element::Type  type,
const Node node = fl::null 
) const
virtual

Computes the size of the subtree under the given node whose elements are of the given type.

The complexity of calling this method is O(n).

Parameters
typeis the type of elements to account for
nodeis the root of the subtree, which is this node if fl::null is given
Returns

Member Data Documentation

◆ element

FL_unique_ptr<Element> fl::Function::Node::element

The node takes an operation or a function.

Definition at line 141 of file Function.h.

◆ left

FL_unique_ptr<Node> fl::Function::Node::left

The node can have an expression tree on the left.

Definition at line 143 of file Function.h.

◆ right

FL_unique_ptr<Node> fl::Function::Node::right

The node can have an expression tree on the right.

Definition at line 145 of file Function.h.

◆ value

scalar fl::Function::Node::value

The node can take an arbitrary floating-point value.

Definition at line 149 of file Function.h.

◆ variable

std::string fl::Function::Node::variable

The node can refer to a variable by name.

Definition at line 147 of file Function.h.


The documentation for this struct was generated from the following file: