• Main Page
  • Modules
  • Classes
  • Files
  • File List

D:/Projekt/ECF_trunk/ECF/tree/TreeMutNodeComplement.cpp

00001 #include "../ECF_base.h"
00002 #include "Tree.h"
00003 #include "TreeMutNodeComplement.h"
00004 #include <stdio.h>
00005 
00006 
00007 namespace Tree
00008 {
00009 
00010 void TreeMutNodeComplement::registerParameters(StateP state)
00011 {
00012     myGenotype_->registerParameter(state, "mut.nodecomplement", (voidP) new double(0), ECF::DOUBLE);
00013 }
00014 
00015 
00016 bool TreeMutNodeComplement::initialize(StateP state)
00017 {
00018     voidP sptr = myGenotype_->getParameterValue(state, "mut.nodecomplement");
00019     probability_ = *((double*)sptr.get());
00020     return true;
00021 }
00022 
00023 
00024 bool TreeMutNodeComplement::mutate(GenotypeP gene)
00025 {
00026     Tree* tree = (Tree*) (gene.get());
00027 
00028     // try to select a random node whose complement is in primitive set
00029     uint tries = 0;
00030     uint index;
00031     std::string name, complementName;
00032     PrimitiveP complement;
00033     do {
00034         index = state_->getRandomizer()->getRandomInteger((int) tree->size());
00035         name = tree->at(index)->primitive_->getName();
00036         complementName = tree->at(index)->primitive_->getComplementName();
00037         
00038         complement = tree->primitiveSet_->getPrimitiveByName(complementName);
00039         tries++;
00040     } while(complement == PrimitiveP() && tries < 4);
00041 
00042     if(complement == PrimitiveP()) {
00043         ECF_LOG(state_, 5, "TreeMutNodeComplement not successful.");
00044         return false;
00045     }
00046 
00047     tree->at(index)->setPrimitive(complement);
00048 
00049     std::stringstream log;
00050     log << "TreeMutNodeComplement successful (oldNode = " << name << ", ";
00051     log << "newNode = " << complementName << ")";
00052     ECF_LOG(state_, 5, log.str());
00053 
00054     return true;
00055 }
00056 
00057 }

Generated on Tue Nov 4 2014 13:04:31 for ECF by  doxygen 1.7.1