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