00001 #include "../ECF_base.h"
00002 #include "Binary.h"
00003
00004 namespace Binary
00005 {
00006
00007 void BinaryCrsUniform::registerParameters(StateP state)
00008 {
00009 myGenotype_->registerParameter(state, "crx.uniform", (voidP) new double(0), ECF::DOUBLE);
00010 }
00011
00012
00013 bool BinaryCrsUniform::initialize(StateP state)
00014 {
00015 voidP sptr = myGenotype_->getParameterValue(state, "crx.uniform");
00016 probability_ = *((double*)sptr.get());
00017 return true;
00018 }
00019
00020
00021 bool BinaryCrsUniform::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 for (uint dimension = 0; dimension < p1->variables.size(); dimension++) {
00028 for(uint i = 0; i < p1->getNumBits(); i++) {
00029 if (p1->variables[dimension][i] == p2->variables[dimension][i])
00030 ch->variables[dimension][i] = p1->variables[dimension][i];
00031 else
00032 ch->variables[dimension][i] = state_->getRandomizer()->getRandomInteger(2) ? true:false;
00033 }
00034 }
00035
00036 ch->update();
00037
00038 return true;
00039 }
00040
00041 }