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

D:/Projekt/ECF_trunk/ECF/binary/BinaryCrsNonGeometric.cpp

00001 #include "../ECF_base.h"
00002 #include "Binary.h"
00003 
00004 namespace Binary
00005 {
00006 
00007 void BinaryCrsNonGeometric::registerParameters(StateP state)
00008 {
00009     myGenotype_->registerParameter(state, "crx.nongeometric", (voidP) new double(0), ECF::DOUBLE);
00010 }
00011 
00012 
00013 bool BinaryCrsNonGeometric::initialize(StateP state)
00014 {
00015     voidP sptr = myGenotype_->getParameterValue(state, "crx.nongeometric");
00016     probability_ = *((double*)sptr.get());
00017 
00018     return true;
00019 }
00020 
00021 
00022 /*
00023 Step 1: Let zi := xi for i =1,2, ...,n (i.e., z is a copy of the
00024         primary parent x).
00025 Step 2: Let zi := (1 - zi) with a probability PBF when xi = yi
00026         where PBF is a prespecified bit-flip probability.
00027 Note:   Random primary parent selection
00028 */
00029 bool BinaryCrsNonGeometric::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
00030 {
00031     Binary* p1 = (Binary*) (gen1.get());
00032     Binary* p2 = (Binary*) (gen2.get());
00033     Binary* ch = (Binary*) (child.get());
00034     
00035     double PBF = 0.5; //prespecified bit-flip probability
00036 
00037     //Step 1
00038     for (uint dimension = 0; dimension < p1->variables.size(); dimension++) {
00039         switch (state_->getRandomizer()->getRandomInteger(0, 1)) {
00040             case 0: for (uint i = 0; i < p1->getNumBits(); i++) {
00041                         ch->variables[dimension][i] = p1->variables[dimension][i];
00042                     }
00043                     break;
00044             case 1: for (uint i = 0; i < p2->getNumBits(); i++) {
00045                         ch->variables[dimension][i] = p2->variables[dimension][i];
00046                     }
00047         }
00048         //Step 2
00049         for(uint i = 0; i < p1->getNumBits(); i++) {
00050             if (p1->variables[dimension][i] == p2->variables[dimension][i]) {
00051                 double changeProbability = state_->getRandomizer()->getRandomDouble();
00052                 if (changeProbability > PBF)
00053                     ch->variables[dimension][i] =  ch->variables[dimension][i]  ? false:true;               
00054             }
00055         }
00056     }
00057 
00058     // update integer and real domain representation
00059     ch->update();
00060 
00061     return true;
00062 }
00063 
00064 }

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