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