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

D:/Projekt/ECF_trunk/ECF/bitstring/BitStringMutSimple.cpp

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

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