00001 #include "../ECF_base.h" 00002 #include "Binary.h" 00003 00004 namespace Binary 00005 { 00006 00007 void BinaryCrsReducedSurrogate::registerParameters(StateP state) 00008 { 00009 myGenotype_->registerParameter(state, "crx.reducedsurrogate", (voidP) new double(0), ECF::DOUBLE); 00010 } 00011 00012 00013 bool BinaryCrsReducedSurrogate::initialize(StateP state) 00014 { 00015 voidP sptr = myGenotype_->getParameterValue(state, "crx.reducedsurrogate"); 00016 probability_ = *((double*)sptr.get()); 00017 return true; 00018 } 00019 00020 00021 bool BinaryCrsReducedSurrogate::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child) 00022 { 00023 Binary* p1 = (Binary*) (gen1.get()); 00024 Binary* p2 = (Binary*) (gen2.get()); 00025 Binary* ch = (Binary*) (child.get()); 00026 00027 for (uint dimension = 0; dimension < p1->variables.size(); dimension++) { 00028 00029 std::vector<int> reduced; 00030 for(uint i = 0; i < p1->getNumBits(); i++) { 00031 if (p1->variables[dimension][i] != p2->variables[dimension][i]) 00032 reduced.push_back(i); 00033 } 00034 00035 uint bitCrs; 00036 int location=-1; 00037 00038 if (reduced.size() > 0 ) { 00039 location = state_->getRandomizer()->getRandomInteger((int) reduced.size()); 00040 bitCrs=reduced[location]; 00041 } 00042 00043 uint parent = state_->getRandomizer()->getRandomInteger(0, 1); 00044 00045 for(uint i = 0; i < p1->getNumBits(); i++) { 00046 if (p1->variables[dimension][i] == p2->variables[dimension][i]) 00047 ch->variables[dimension][i] = p1->variables[dimension][i]; 00048 else { 00049 if (parent==0) { 00050 if (i < bitCrs) 00051 ch->variables[dimension][i] = p1->variables[dimension][i]; 00052 else 00053 ch->variables[dimension][i] = p2->variables[dimension][i]; 00054 } 00055 else { 00056 if (i < bitCrs) 00057 ch->variables[dimension][i] = p2->variables[dimension][i]; 00058 else 00059 ch->variables[dimension][i] = p1->variables[dimension][i]; 00060 } 00061 } 00062 } 00063 } 00064 00065 ch->update(); 00066 00067 return true; 00068 } 00069 00070 }