00001 #include "../ECF_base.h"
00002 #include "Binary.h"
00003
00004 namespace Binary
00005 {
00006
00007 void BinaryCrsHalfUniform::registerParameters(StateP state)
00008 {
00009 myGenotype_->registerParameter(state, "crx.halfuniform", (voidP) new double(0), ECF::DOUBLE);
00010 }
00011
00012
00013 bool BinaryCrsHalfUniform::initialize(StateP state)
00014 {
00015 voidP sptr = myGenotype_->getParameterValue(state, "crx.halfuniform");
00016 probability_ = *((double*)sptr.get());
00017 return true;
00018 }
00019
00020
00021 bool BinaryCrsHalfUniform::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
00022 {
00023 Binary* p1 = (Binary*) (gen1.get());
00024 Binary* p2 = (Binary*) (gen2.get());
00025 Binary* ch = (Binary*) (child.get());
00026
00027 uint counter = 0;
00028 for (uint dimension = 0; dimension < p1->variables.size(); dimension++) {
00029 for(uint i = 0; i < p1->getNumBits(); i++) {
00030 if (p1->variables[dimension][i] != p2->variables[dimension][i])
00031 counter++;
00032 }
00033
00034 counter = (uint) counter/2;
00035 uint parent = state_->getRandomizer()->getRandomInteger(0, 1);
00036
00037 for(uint i = 0; i < p1->getNumBits(); i++) {
00038 if (p1->variables[dimension][i] == p2->variables[dimension][i])
00039 ch->variables[dimension][i] = p1->variables[dimension][i];
00040 else {
00041 if (counter !=0) {
00042 ch->variables[dimension][i] = state_->getRandomizer()->getRandomInteger(2) ? true:false;
00043 counter--;
00044 }
00045 else {
00046 if (parent == 0)
00047 ch->variables[dimension][i] = p1->variables[dimension][i];
00048 else
00049 ch->variables[dimension][i] = p2->variables[dimension][i];
00050 }
00051 }
00052 }
00053 counter = 0;
00054 }
00055
00056 ch->update();
00057
00058 return true;
00059 }
00060
00061 }