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
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
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
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 return true;
00099 }
00100
00101 }