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
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
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 }