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