Base primitive class (Tree genotype). More...
#include <Primitive.h>
Public Member Functions | |
virtual void | execute (void *result, Tree &tree)=0 |
Execute the primitive. | |
virtual bool | initialize (StateP state) |
Initialize the primitive (default just sets the StateP pointer). | |
virtual void | setValue (void *value) |
virtual void | getValue (void *value) |
virtual PrimitiveP | copyWithNode (PrimitiveP) |
Copy primitive (when copying a node, e.g. in crossover). The default behaviour just returns the same pointer (common primitives). (ERC's should override and make a new copy of the original object). | |
virtual PrimitiveP | assignToNode (PrimitiveP) |
Assign primitive to node (when building a tree). The default behaviour just returns the same pointer (common primitives). ERC's should override and generate a new object with a new value. | |
void | getNextArgument (void *result, Tree &tree) |
Execute next child node's primitive (execute next subtree). | |
void | skipNextArgument (Tree &tree) |
Skip next child subtree (doesn't execute the subtree). | |
int | getNumberOfArguments () |
Return primitive's number of arguments. | |
void | setName (std::string name) |
Set primitive's name. | |
std::string | getName () |
Get primitive's name. | |
std::string | getComplementName () |
Get complement's name. | |
Public Attributes | |
StateP | state_ |
Protected Attributes | |
std::string | name_ |
int | nArguments_ |
std::string | complementName_ |
Base primitive class (Tree genotype).
Each node of a tree points to a single primitive, which may be a function or a variable (of Terminal class). Some primitives are shared among all the trees (i.e. have the same value and functionality), but some (like ERC) are owned by a single Tree.
Definition at line 36 of file Primitive.h.
PrimitiveP Tree::Primitives::Primitive::assignToNode | ( | PrimitiveP | primitive | ) | [virtual] |
Assign primitive to node (when building a tree). The default behaviour just returns the same pointer (common primitives). ERC's should override and generate a new object with a new value.
sptr | to this primitive |
Reimplemented in Tree::Primitives::ERC< T >, Tree::Primitives::ERCD, and Tree::Primitives::ERC< double >.
Definition at line 36 of file Primitive.cpp.
PrimitiveP Tree::Primitives::Primitive::copyWithNode | ( | PrimitiveP | primitive | ) | [virtual] |
Copy primitive (when copying a node, e.g. in crossover). The default behaviour just returns the same pointer (common primitives). (ERC's should override and make a new copy of the original object).
sptr | to this primitive |
Reimplemented in Tree::Primitives::ERC< T >, and Tree::Primitives::ERC< double >.
Definition at line 60 of file Primitive.cpp.
virtual void Tree::Primitives::Primitive::execute | ( | void * | result, | |
Tree & | tree | |||
) | [pure virtual] |
Execute the primitive.
Function primitives gather arguments and return a value; terminal primitives return current value.
Implemented in Tree::MyTerminal, Tree::MyFunc, Tree::Primitives::AddT< T >, Tree::Primitives::Cos, Tree::Primitives::DivT< T >, Tree::Primitives::MaxT< T >, Tree::Primitives::MinT< T >, Tree::Primitives::MulT< T >, Tree::Primitives::NegT< T >, Tree::Primitives::PosT< T >, Tree::Primitives::Sin, Tree::Primitives::SubT< T >, Tree::Primitives::TerminalT< T >, Tree::Primitives::ERC< T >, IfFoodAhead, MoveAhead, Prog2, Prog3, TurnLeft, TurnRight, and Tree::Primitives::ERC< double >.
void Tree::Primitives::Primitive::getNextArgument | ( | void * | result, | |
Tree & | tree | |||
) |
Execute next child node's primitive (execute next subtree).
result | result of the operation | |
tree | reference to current tree |
Definition at line 71 of file Primitive.cpp.
void Tree::Primitives::Primitive::skipNextArgument | ( | Tree & | tree | ) |
Skip next child subtree (doesn't execute the subtree).
tree | reference to current tree |
Definition at line 82 of file Primitive.cpp.