1#include "../ECF_base.h" 
    3#include "TreeMutSubtree.h" 
   12    myGenotype_->registerParameter(state, 
"mut.subtree", (voidP) 
new double(0), ECF::DOUBLE);
 
   18    voidP sptr = 
myGenotype_->getParameterValue(state, 
"mut.subtree");
 
   31    uint chosenNodeSubtreeSize;
 
   35        chosenNode = state_->getRandomizer()->getRandomInteger((
int) tree->size());
 
   36        chosenNodeSubtreeSize = tree->at(chosenNode)->size_;
 
   37        chosenNodeDepth = tree->at(chosenNode)->depth_;
 
   39    } 
while((chosenNodeDepth == tree->maxDepth_) && tries < 4);
 
   42        ECF_LOG(state_, 5, 
"TreeMutSubtree not successful.");
 
   47    Tree* copyTree = tree->copy();
 
   50    std::stringstream log;
 
   51    log << 
"TreeMutSubtree successful (";
 
   56    for( ; i < chosenNode; i++) {
 
   57        NodeP 
node = 
static_cast<NodeP
> (
new Node(copyTree->at(i)->primitive_));
 
   61    log << 
"mutatedSubtree(at depth " << chosenNodeDepth << 
") = ";
 
   62    for( ; i < chosenNode + chosenNodeSubtreeSize; i++) {
 
   64        log << copyTree->at(i)->primitive_->getName() << 
" ";
 
   69    Tree* newTree = tree->copy();
 
   71    newTree->initMinDepth_ = 0;
 
   72    newTree->initMaxDepth_ = copyTree->maxDepth_ - chosenNodeDepth;
 
   74    if(state_->getRandomizer()->getRandomInteger(0, 1) % 2 == 0)
 
   75        newTree->fullBuild(copyTree->primitiveSet_);
 
   77        newTree->growBuild(copyTree->primitiveSet_);
 
   79    log << 
", newSubtree = ";
 
   81    for(uint j = 0; j < newTree->size(); j++) {
 
   82        NodeP 
node = 
static_cast<NodeP
> (
new Node(newTree->at(j)->primitive_));
 
   84        log << 
node->primitive_->getName() << 
" ";
 
   89    for( ; i < copyTree->size(); i++) {
 
   90        NodeP 
node = 
static_cast<NodeP
> (
new Node(copyTree->at(i)->primitive_));
 
   98    ECF_LOG(state_, 5, log.str());
 
double probability_
probability of usage of this mutation operator
 
GenotypeP myGenotype_
pointer to the Genotype that defines this MutationOp
 
Node base class (Tree genotype)
 
Tree class - implements genotype as a tree.
 
bool mutate(GenotypeP gene)
Performs mutation of a genotype object. The genotype object must be initialized!
 
bool initialize(StateP)
Initialize mutation operator. Called before first mutation operation.
 
void registerParameters(StateP)
Register parameters with the system. Called before MutationOp::initialize.