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

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

00001 #include "../ECF_base.h"
00002 #include "FloatingPoint.h"
00003 
00004 namespace FloatingPoint
00005 {
00006 
00007 void FloatingPointCrsArithmetic::registerParameters(StateP state)
00008 {
00009     myGenotype_->registerParameter(state, "crx.arithmetic", (voidP) new double(0), ECF::DOUBLE);
00010 }
00011 
00012 
00013 bool FloatingPointCrsArithmetic::initialize(StateP state)
00014 {
00015     voidP sptr = myGenotype_->getParameterValue(state, "crx.arithmetic");
00016     probability_ = *((double*)sptr.get());
00017     return true;
00018 }
00019 
00020 
00021 bool FloatingPointCrsArithmetic::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
00022 {
00023     FloatingPoint* p1 = (FloatingPoint*) (gen1.get());
00024     FloatingPoint* p2 = (FloatingPoint*) (gen2.get());
00025     FloatingPoint* ch = (FloatingPoint*) (child.get());
00026 
00027     double a = state_->getRandomizer()->getRandomDouble();
00028 
00029     switch (state_->getRandomizer()->getRandomInteger(0, 1)) {
00030         case 0: for (uint i = 0; i < p1->realValue.size(); i++) {
00031                     ch->realValue[i] = a * (p1->realValue[i]) + (1 - a) * (p2->realValue[i]);
00032                 }
00033                 break;
00034         case 1: for (uint i = 0; i < p1->realValue.size(); i++) {
00035                     ch->realValue[i] = a * (p2->realValue[i]) + (1 - a) * (p1->realValue[i]);
00036                 }
00037     }
00038 
00039     return true;
00040 }
00041 
00042 }

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