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