00001 #include "../ECF_base.h"
00002 #include "FloatingPoint.h"
00003 #include <math.h>
00004
00005 namespace FloatingPoint
00006 {
00007
00008 void FloatingPointCrsBga::registerParameters(StateP state)
00009 {
00010 myGenotype_->registerParameter(state, "crx.bga", (voidP) new double(0), ECF::DOUBLE);
00011 }
00012
00013
00014 bool FloatingPointCrsBga::initialize(StateP state)
00015 {
00016 voidP sptr = myGenotype_->getParameterValue(state, "crx.bga");
00017 probability_ = *((double*)sptr.get());
00018
00019 return true;
00020 }
00021
00022
00023 bool FloatingPointCrsBga::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
00024 {
00025 FloatingPoint* p1 = (FloatingPoint*) (gen1.get());
00026 FloatingPoint* p2 = (FloatingPoint*) (gen2.get());
00027 FloatingPoint* ch = (FloatingPoint*) (child.get());
00028
00029 int a;
00030
00031 double rang = 0.5 * (p1->getUBound() - p1->getLBound());
00032
00033 double gama = 0, lambda = 0, b;
00034 for (int i = 0; i <= 15; i++) {
00035 a = state_->getRandomizer()->getRandomInteger(1, 16);
00036 if (a == 16)
00037 a = 1;
00038 else
00039 a = 0;
00040 gama = gama + a * pow((double) 2., -i);
00041 }
00042
00043 for (uint i = 0; i < p1->realValue.size(); i++) {
00044
00045 lambda = (p2->realValue[i] - p1->realValue[i])/1;
00046 b = state_->getRandomizer()->getRandomDouble();
00047 if (b <= 0.9)
00048 ch->realValue[i] = p1->realValue[i] - rang * gama * lambda;
00049 else
00050 ch->realValue[i] = p1->realValue[i] + rang * gama * lambda;
00051 }
00052
00053 return true;
00054 }
00055
00056 }