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