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

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

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

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