ECF 1.5
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Tree::Tree Class Reference

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

#include <Tree_c.h>

Inheritance diagram for Tree::Tree:
Genotype Tree::IATree Tree::MyTree

Public Member Functions

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

Public Attributes

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

Protected Member Functions

uint growBuild (PrimitiveSetP primitiveSet, uint myDepth)
 Build Tree using 'grow' method. More...
 
uint fullBuild (PrimitiveSetP primitiveSet, uint myDepth)
 Build Tree using 'full' method. More...
 
uint setSize (uint)
 Calculate subtree sizes of each node in the tree. More...
 
void setDepth (uint myDepth)
 Calculate depth of each node in the tree. More...
 
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. More...
 

Protected Attributes

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

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.

Reimplemented in Tree::MyTree, and Tree::IATree.

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.

Reimplemented in Tree::MyTree.

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.

Reimplemented in Tree::MyTree.

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.

Reimplemented in Tree::MyTree.

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

Reimplemented in Tree::IATree.

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  )
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 ( void  )

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: