00001 #include "../ECF_base.h"
00002 #include "Binary.h"
00003
00004 namespace Binary
00005 {
00006
00007 void BinaryCrsOnePoint::registerParameters(StateP state)
00008 {
00009 myGenotype_->registerParameter(state, "crx.onepoint", (voidP) new double(0), ECF::DOUBLE);
00010 }
00011
00012
00013 bool BinaryCrsOnePoint::initialize(StateP state)
00014 {
00015 voidP sptr = myGenotype_->getParameterValue(state, "crx.onepoint");
00016 probability_ = *((double*)sptr.get());
00017 return true;
00018 }
00019
00020
00021 bool BinaryCrsOnePoint::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 bitCrs = state_->getRandomizer()->getRandomInteger(p1->getNumBits());
00028
00029 for (uint dimension = 0; dimension < p1->variables.size(); dimension++) {
00030 switch (state_->getRandomizer()->getRandomInteger(0, 1)) {
00031 case 0: for (uint i = 0; i < bitCrs; i++) {
00032 ch->variables[dimension][i] = p1->variables[dimension][i];
00033 }
00034 for (uint i = bitCrs; i < p2->getNumBits(); i++) {
00035 ch->variables[dimension][i] = p2->variables[dimension][i];
00036 }
00037 break;
00038 case 1: for (uint i = 0; i < bitCrs; i++) {
00039 ch->variables[dimension][i] = p2->variables[dimension][i];
00040 }
00041 for (uint i = bitCrs; i < p1->getNumBits(); i++) {
00042 ch->variables[dimension][i] = p1->variables[dimension][i];
00043 }
00044 }
00045 }
00046
00047
00048 ch->update();
00049
00050 return true;
00051 }
00052
00053 }