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