1#include "../ECF_base.h"
3#include "TreeMutShrink.h"
12 myGenotype_->registerParameter(state,
"mut.shrink", (voidP)
new double(0), ECF::DOUBLE);
18 voidP sptr =
myGenotype_->getParameterValue(state,
"mut.shrink");
31 uint chosenNodeSubtreeSize;
34 chosenNode = state_->getRandomizer()->getRandomInteger((
int) tree->size());
35 chosenNodeSubtreeSize = tree->at(chosenNode)->size_;
37 }
while(chosenNodeSubtreeSize == 1 && tries < 4);
39 if(chosenNodeSubtreeSize == 1) {
40 ECF_LOG(state_, 5,
"TreeMutShrink not successful.");
45 Tree* copyTree = tree->copy();
48 std::stringstream log;
49 log <<
"TreeMutShrink successful (";
54 for( ; i < chosenNode; i++) {
55 NodeP
node =
static_cast<NodeP
> (
new Node(copyTree->at(i)->primitive_));
59 log <<
"shrinkedSubtree = ";
60 for( ; i < chosenNode + chosenNodeSubtreeSize; i++) {
62 log << copyTree->at(i)->primitive_->getName() <<
" ";
67 node->setPrimitive(copyTree->primitiveSet_->getRandomTerminal());
69 log <<
", shrinkedTo = " <<
node->primitive_->getName() <<
")";
72 for( ; i < copyTree->size(); i++) {
73 NodeP
node =
static_cast<NodeP
> (
new Node(copyTree->at(i)->primitive_));
80 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 initialize(StateP)
Initialize mutation operator. Called before first mutation operation.
void registerParameters(StateP)
Register parameters with the system. Called before MutationOp::initialize.
bool mutate(GenotypeP gene)
Performs mutation of a genotype object. The genotype object must be initialized!