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

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

00001 #include "../ECF_base.h"
00002 #include "FloatingPoint.h"
00003 #include <math.h>
00004 
00005 namespace FloatingPoint
00006 {
00007 
00008 void FloatingPointCrsSbx::registerParameters(StateP state)
00009 {
00010     myGenotype_->registerParameter(state, "crx.sbx", (voidP) new double(0), ECF::DOUBLE);
00011     state->getRegistry()->registerEntry("ni", (voidP) new uint(1), ECF::UINT);
00012 }
00013 
00014 
00015 bool FloatingPointCrsSbx::initialize(StateP state)
00016 {
00017     voidP sptr = myGenotype_->getParameterValue(state, "crx.sbx");
00018     probability_ = *((double*)sptr.get());
00019 
00020     voidP par = state->getRegistry()->getEntry("ni");
00021     ni = *((uint*) par.get());
00022 
00023     return true;
00024 }
00025 
00026 
00027 bool FloatingPointCrsSbx::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
00028 {
00029     FloatingPoint* p1 = (FloatingPoint*) (gen1.get());
00030     FloatingPoint* p2 = (FloatingPoint*) (gen2.get());
00031     FloatingPoint* ch = (FloatingPoint*) (child.get());
00032 
00033     double u = state_->getRandomizer()->getRandomDouble();
00034     double beta = 0.0;
00035     
00036     if (u < 0.5) { // if u is smaller than 0.5 perform a contracting crossover
00037         beta = pow(2 * u, 1.0 / (ni + 1.0));
00038     }
00039     else { // otherwise perform an expanding crossover
00040         beta = pow(0.5 / (1.0 - u), 1.0 / (ni + 1.0));
00041     }
00042 
00043     double a = state_->getRandomizer()->getRandomDouble();
00044 
00045     switch (state_->getRandomizer()->getRandomInteger(0, 1)) {
00046         case 0: for (uint i = 0; i < p1->realValue.size(); i++) {
00047                     ch->realValue[i] = ((p1->realValue[i] + p2->realValue[i])/2.0) - beta * 0.5 * fabs(p1->realValue[i] - p2->realValue[i]);
00048                 }
00049                 break;
00050         case 1: for (uint i = 0; i < p1->realValue.size(); i++) {
00051                     ch->realValue[i] = ((p1->realValue[i] + p2->realValue[i])/2.0) + beta * 0.5 * fabs(p1->realValue[i] - p2->realValue[i]);
00052                 }
00053     }
00054 
00055     return true;
00056 }
00057 
00058 }

Generated on Fri Jul 5 2013 09:34:23 for ECF by  doxygen 1.7.1