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
00024
00025
00026
00027
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;
00036
00037
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
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
00059 ch->update();
00060
00061 return true;
00062 }
00063
00064 }