• Main Page
  • Modules
  • Classes
  • Files
  • File List

D:/Projekt/ECF_trunk/ECF/floatingpoint/FloatingPointCrsBlx.cpp

00001 #include "../ECF_base.h"
00002 #include "FloatingPoint.h"
00003 
00004 
00005 namespace FloatingPoint
00006 {
00007 
00008 void FloatingPointCrsBlx::registerParameters(StateP state)
00009 {
00010     myGenotype_->registerParameter(state, "crx.blx", (voidP) new double(0), ECF::DOUBLE);
00011     myGenotype_->registerParameter(state, "crx.blx.alpha", (voidP) new double(0.5), ECF::DOUBLE);
00012 }
00013 
00014 
00015 bool FloatingPointCrsBlx::initialize(StateP state)
00016 {
00017     voidP sptr = myGenotype_->getParameterValue(state, "crx.blx");
00018     probability_ = *((double*)sptr.get());
00019 
00020     useAlpha = false;
00021     if(myGenotype_->isParameterDefined(state, "crx.blx.alpha"))
00022         useAlpha = true;
00023 
00024     sptr = myGenotype_->getParameterValue(state, "crx.blx.alpha");
00025     alpha = *((double*)sptr.get());
00026 
00027     return true;
00028 }
00029 
00030 
00031 bool FloatingPointCrsBlx::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
00032 {
00033     FloatingPoint* p1 = (FloatingPoint*) (gen1.get());
00034     FloatingPoint* p2 = (FloatingPoint*) (gen2.get());
00035     FloatingPoint* ch = (FloatingPoint*) (child.get());
00036 
00037     double min1, max1, min2, max2, min, max, a, b, I;
00038 
00039     min1 = p1->realValue[0];
00040     max1 = p1->realValue[0];
00041     min2 = p2->realValue[0];
00042     max2 = p2->realValue[0];
00043     for (uint i = 1; i < p1->realValue.size(); i++) {
00044         if (p1->realValue[i] < min1)
00045             min1 = p1->realValue[i];
00046         if (p1->realValue[i] > max1)
00047             max1 = p1->realValue[i];
00048 
00049         if (p2->realValue[i] < min2)
00050             min2 = p2->realValue[i];
00051         if (p2->realValue[i] > max2)
00052             max2 = p2->realValue[i];
00053     }
00054     min = (min1 < min2)?min1:min2;
00055     max = (max1 > max2)?max1:max2;
00056     if(useAlpha)
00057         b = alpha;
00058     else
00059         b = state_->getRandomizer()->getRandomDouble();
00060     I = max - min;
00061     min = min - I*b;
00062     max = max + I*b;
00063     for (uint i = 0; i < p1->realValue.size(); i++) {
00064         a = state_->getRandomizer()->getRandomDouble();
00065         a = min + a*(max-min); // s obzirom da nema tako neceg u SimpleRandomizeru dodao sam ovdje
00066         ch->realValue[i] = a;
00067     }
00068 
00069     return true;
00070 }
00071 
00072 }

Generated on Tue Nov 4 2014 13:04:31 for ECF by  doxygen 1.7.1