00001 #include "../ECF_base.h"
00002 #include "FloatingPoint.h"
00003 #include<cmath>
00004
00005
00006 namespace FloatingPoint
00007 {
00008
00009 void FloatingPointCrsBlxAlphaBeta::registerParameters(StateP state)
00010 {
00011 myGenotype_->registerParameter(state, "crx.blxalphabeta", (voidP) new double(0), ECF::DOUBLE);
00012 state->getRegistry()->registerEntry("alpha", (voidP) new double(0.75), ECF::DOUBLE);
00013 state->getRegistry()->registerEntry("beta", (voidP) new double(0.25), ECF::DOUBLE);
00014 }
00015
00016
00017 bool FloatingPointCrsBlxAlphaBeta::initialize(StateP state)
00018 {
00019 voidP sptr = myGenotype_->getParameterValue(state, "crx.blxalphabeta");
00020 probability_ = *((double*)sptr.get());
00021
00022 voidP par = state->getRegistry()->getEntry("alpha");
00023 alpha = *((uint*) par.get());
00024
00025 par = state->getRegistry()->getEntry("beta");
00026 beta = *((uint*) par.get());
00027
00028 return true;
00029 }
00030
00031
00032 bool FloatingPointCrsBlxAlphaBeta::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
00033 {
00034 FloatingPoint* p1 = (FloatingPoint*) (gen1.get());
00035 FloatingPoint* p2 = (FloatingPoint*) (gen2.get());
00036 FloatingPoint* ch = (FloatingPoint*) (child.get());
00037
00038 double min = 0, max = 0, a, I;
00039
00040 for (uint i = 1; i < p1->realValue.size(); i++) {
00041 a = state_->getRandomizer()->getRandomDouble();
00042
00043 I = fabs(p1->realValue[i] - p2->realValue[i]);
00044
00045 if (p1->realValue[i] <= p2->realValue[i]){
00046 min = p1->realValue[i] - I*alpha;
00047 max = p2->realValue[i] + I*beta;
00048 }
00049 else{
00050 min = p2->realValue[i] - I*beta;
00051 max = p1->realValue[i] + I*alpha;
00052 }
00053 ch->realValue[i] = min + a * (max - min);
00054 }
00055
00056 return true;
00057 }
00058
00059 }