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