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

D:/Projekt/ECF_trunk/ECF/binary/BinaryMutSimple.cpp

00001 #include "../ECF_base.h"
00002 #include "Binary.h"
00003 #include <cmath>
00004 
00005 namespace Binary
00006 {
00007 
00008 void BinaryMutSimple::registerParameters(StateP state)
00009 {
00010     myGenotype_->registerParameter(state, "mut.simple", (voidP) new double(0), ECF::DOUBLE);
00011     myGenotype_->registerParameter(state, "mut.simple.bitprob", (voidP) new double(0.001), ECF::DOUBLE);
00012 }
00013 
00014 
00015 bool BinaryMutSimple::initialize(StateP state)
00016 {
00017     voidP sptr = myGenotype_->getParameterValue(state, "mut.simple");
00018     probability_ = *((double*)sptr.get());
00019 
00020     sptr = myGenotype_->getParameterValue(state, "mut.simple.bitprob");
00021     bitProb_ = *((double*)sptr.get());
00022 
00023     bUseBitProb_ = false;
00024     if(myGenotype_->isParameterDefined(state, "mut.simple.bitprob"))
00025         bUseBitProb_ = true;
00026 
00027     return true;
00028 }
00029 
00030 
00031 bool BinaryMutSimple::mutate(GenotypeP gene)
00032 {
00033     Binary* bin = (Binary*) (gene.get());
00034 
00035     // invert all bits with 'bitProb_' probability
00036     if(bUseBitProb_) {
00037         for(uint i = 0; i < bin->variables.size(); i++)
00038             for(uint j = 0; j < bin->getNumBits(); j++)
00039                 if(state_->getRandomizer()->getRandomDouble() < bitProb_)
00040                     bin->variables[i][j] = !(bin->variables[i][j]);
00041     }
00042     // invert a single random bit in the genotype
00043     else {
00044         uint iBit = state_->getRandomizer()->getRandomInteger((uint) bin->getNumBits());
00045         uint dimension = state_->getRandomizer()->getRandomInteger((uint) bin->variables.size());
00046         bin->variables[dimension][iBit] = !(bin->variables[dimension][iBit]);
00047     }
00048 
00049     bin->update();
00050 
00051     return true;
00052 }
00053 
00054 }

Generated on Thu Oct 6 2011 13:41:00 for ECF by  doxygen 1.7.1