ECF 1.7
Tree::Tree Class Reference

Tree class - implements genotype as a tree. More...

#include <Tree_c.h>

Inheritance diagram for Tree::Tree:
Genotype

Public Member Functions

Tree * copy ()
 Create an identical copy of the genotype object.
void growBuild (PrimitiveSetP primitiveSet)
 Build tree with grow method.
void fullBuild (PrimitiveSetP primitiveSet)
 Build tree with full method.
void update ()
 Calculate depth and subtree sizes of each node in the tree.
void execute (void *)
 Execute current tree.
void addNode (Node *node)
void addNode (NodeP node)
void setTerminalValue (std::string, void *)
 Set a terminal's value.
void getTerminalValue (std::string, void *)
 Retrieve a terminal's value.
void write (XMLNode &)
 Write genotype data to XMLNode.
void read (XMLNode &)
 Read genotype data from XMLNode.
void registerParameters (StateP)
 Register genotype's parameters (called before Genotype::initialize).
bool initialize (StateP state)
 Initialize a genotype object (read parameters, perform sanity check, build data).
std::vector< MutationOpP > getMutationOp ()
 Create and return a vector of mutation operators.
std::vector< CrossoverOpP > getCrossoverOp ()
 Create and return a vector of crossover operators.
bool addFunction (PrimitiveP)
 Add user defined function primitive. Must be called prior to initialization (no impact otherwise).
bool addTerminal (PrimitiveP)
 Add user defined terminal primitive. Must be called prior to initialization (no impact otherwise).
uint getMaxDepth ()
uint getMinDepth ()
uint getStartDepth ()
Public Member Functions inherited from Genotype
bool registerParameter (StateP state, std::string name, voidP value, enum ECF::type T, std::string description="")
 Register a single parameter.
voidP getParameterValue (StateP state, std::string name)
 Read single parameter value from Registry.
bool setParameterValue (StateP state, std::string name, voidP value)
 Write single parameter value to Registry.
bool isParameterDefined (StateP state, std::string name)
 Check if parameter is defined in the configuration.
virtual uint getGenomeSize ()
std::string getName ()
 Return genotype's name (each genotype is uniquely identified with its name).
uint getGenotypeId ()
 Return this genotype's index in individual structure.
void setGenotypeId (uint id)
 Set genotype index in an individual.
std::string toString ()
 Output genotype to string.

Public Attributes

PrimitiveSetP primitiveSet_
uint iNode_
 current node index (when parsing the tree)
uint startDepth_
 start depth of the first node (0 by default)
uint maxDepth_
 max allowed Tree depth
uint minDepth_
 min allowed Tree depth
uint initMaxDepth_
 max allowed Tree depth at initialization (maxDepth_ used if not defined)
uint initMinDepth_
 min allowed Tree depth at initialization (minDepth_ used if not defined)

Protected Member Functions

uint growBuild (PrimitiveSetP primitiveSet, uint myDepth)
 Build Tree using 'grow' method.
uint fullBuild (PrimitiveSetP primitiveSet, uint myDepth)
 Build Tree using 'full' method.
uint setSize (uint)
 Calculate subtree sizes of each node in the tree.
void setDepth (uint myDepth)
 Calculate depth of each node in the tree.
virtual void initializeFirst (Tree *hometree)
 Performs the first Tree initialization (performed only once for each active Tree Genotype). Constructs the primitive set and performs parameter checks.

Protected Attributes

std::vector< PrimitiveP > userFunctions_
std::vector< PrimitiveP > userTerminals_
StateP state_
Protected Attributes inherited from Genotype
std::string name_
 genotype's name
uint genotypeId_
 this genotype's unique index in individual structure

Detailed Description

Tree class - implements genotype as a tree.

Tree inherits a vector of Node objects. Each node points to a Primitive object. Nodes in tree are aligned in a prefix notation. Some primitives are shared among all the trees, but some (such as ERC primitives) belong to a single Tree.

Definition at line 28 of file Tree_c.h.

Constructor & Destructor Documentation

◆ Tree()

Tree::Tree::Tree ( void )

Definition at line 26 of file Tree.cpp.

◆ ~Tree()

Tree::Tree::~Tree ( void )

Definition at line 33 of file Tree.cpp.

Member Function Documentation

◆ addFunction()

bool Tree::Tree::addFunction ( PrimitiveP func)

Add user defined function primitive. Must be called prior to initialization (no impact otherwise).

Definition at line 80 of file Tree.cpp.

◆ addNode() [1/2]

void Tree::Tree::addNode ( Node * node)

Definition at line 369 of file Tree.cpp.

◆ addNode() [2/2]

void Tree::Tree::addNode ( NodeP node)

Definition at line 375 of file Tree.cpp.

◆ addTerminal()

bool Tree::Tree::addTerminal ( PrimitiveP term)

Add user defined terminal primitive. Must be called prior to initialization (no impact otherwise).

Definition at line 91 of file Tree.cpp.

◆ copy()

Tree * Tree::Tree::copy ( )
virtual

Create an identical copy of the genotype object.

Implements Genotype.

Definition at line 37 of file Tree.cpp.

◆ execute()

void Tree::Tree::execute ( void * result)

Execute current tree.

Evaluates the function embodied in the tree (or executes the represented program).

Parameters
resultthe resulting tree value (of the first node)

Definition at line 362 of file Tree.cpp.

◆ fullBuild() [1/2]

void Tree::Tree::fullBuild ( PrimitiveSetP primitiveSet)

Build tree with full method.

Definition at line 492 of file Tree.cpp.

◆ fullBuild() [2/2]

uint Tree::Tree::fullBuild ( PrimitiveSetP primitiveSet,
uint myDepth )
protected

Build Tree using 'full' method.

Definition at line 382 of file Tree.cpp.

◆ getCrossoverOp()

std::vector< CrossoverOpP > Tree::Tree::getCrossoverOp ( )
virtual

Create and return a vector of crossover operators.

Reimplemented from Genotype.

Definition at line 49 of file Tree.cpp.

◆ getMaxDepth()

uint Tree::Tree::getMaxDepth ( )
inline

Definition at line 65 of file Tree_c.h.

◆ getMinDepth()

uint Tree::Tree::getMinDepth ( )
inline

Definition at line 68 of file Tree_c.h.

◆ getMutationOp()

std::vector< MutationOpP > Tree::Tree::getMutationOp ( )
virtual

Create and return a vector of mutation operators.

Reimplemented from Genotype.

Definition at line 61 of file Tree.cpp.

◆ getStartDepth()

uint Tree::Tree::getStartDepth ( )
inline

Definition at line 71 of file Tree_c.h.

◆ getTerminalValue()

void Tree::Tree::getTerminalValue ( std::string name,
void * value )

Retrieve a terminal's value.

Parameters
nameterminal's name
valueterminal's value

Definition at line 522 of file Tree.cpp.

◆ growBuild() [1/2]

void Tree::Tree::growBuild ( PrimitiveSetP primitiveSet)

Build tree with grow method.

Definition at line 483 of file Tree.cpp.

◆ growBuild() [2/2]

uint Tree::Tree::growBuild ( PrimitiveSetP primitiveSet,
uint myDepth )
protected

Build Tree using 'grow' method.

Definition at line 404 of file Tree.cpp.

◆ initialize()

bool Tree::Tree::initialize ( StateP state)
virtual

Initialize a genotype object (read parameters, perform sanity check, build data).

Implements Genotype.

Definition at line 115 of file Tree.cpp.

◆ initializeFirst()

void Tree::Tree::initializeFirst ( Tree * hometree)
protectedvirtual

Performs the first Tree initialization (performed only once for each active Tree Genotype). Constructs the primitive set and performs parameter checks.

Parameters
hometreeuninitialized Tree instance in vector of active Genotypes stored in State

Definition at line 149 of file Tree.cpp.

◆ read()

void Tree::Tree::read ( XMLNode & )
virtual

Read genotype data from XMLNode.

Implements Genotype.

Definition at line 550 of file Tree.cpp.

◆ registerParameters()

void Tree::Tree::registerParameters ( StateP state)
virtual

Register genotype's parameters (called before Genotype::initialize).

Reimplemented from Genotype.

Definition at line 98 of file Tree.cpp.

◆ setDepth()

void Tree::Tree::setDepth ( uint myDepth)
protected

Calculate depth of each node in the tree.

Definition at line 468 of file Tree.cpp.

◆ setSize()

uint Tree::Tree::setSize ( uint iNode)
protected

Calculate subtree sizes of each node in the tree.

Definition at line 451 of file Tree.cpp.

◆ setTerminalValue()

void Tree::Tree::setTerminalValue ( std::string name,
void * value )

Set a terminal's value.

Parameters
nameterminal's name
valueterminal's value

Definition at line 504 of file Tree.cpp.

◆ update()

void Tree::Tree::update ( )

Calculate depth and subtree sizes of each node in the tree.

Uses recursive depth-first tree processing.

Definition at line 435 of file Tree.cpp.

◆ write()

void Tree::Tree::write ( XMLNode & )
virtual

Write genotype data to XMLNode.

Implements Genotype.

Definition at line 535 of file Tree.cpp.

Member Data Documentation

◆ initMaxDepth_

uint Tree::Tree::initMaxDepth_

max allowed Tree depth at initialization (maxDepth_ used if not defined)

Definition at line 79 of file Tree_c.h.

◆ initMinDepth_

uint Tree::Tree::initMinDepth_

min allowed Tree depth at initialization (minDepth_ used if not defined)

Definition at line 80 of file Tree_c.h.

◆ iNode_

uint Tree::Tree::iNode_

current node index (when parsing the tree)

Definition at line 75 of file Tree_c.h.

◆ maxDepth_

uint Tree::Tree::maxDepth_

max allowed Tree depth

Definition at line 77 of file Tree_c.h.

◆ minDepth_

uint Tree::Tree::minDepth_

min allowed Tree depth

Definition at line 78 of file Tree_c.h.

◆ primitiveSet_

PrimitiveSetP Tree::Tree::primitiveSet_

Definition at line 74 of file Tree_c.h.

◆ startDepth_

uint Tree::Tree::startDepth_

start depth of the first node (0 by default)

Definition at line 76 of file Tree_c.h.

◆ state_

StateP Tree::Tree::state_
protected

Definition at line 39 of file Tree_c.h.

◆ userFunctions_

std::vector<PrimitiveP> Tree::Tree::userFunctions_
protected

Definition at line 37 of file Tree_c.h.

◆ userTerminals_

std::vector<PrimitiveP> Tree::Tree::userTerminals_
protected

Definition at line 38 of file Tree_c.h.


The documentation for this class was generated from the following files: