00001 #include "../ECF_base.h"
00002 #include "Permutation.h"
00003 #include <map>
00004
00005
00006 namespace Permutation
00007 {
00008
00009 void PermutationCrsPBX::registerParameters(StateP state)
00010 {
00011 myGenotype_->registerParameter(state, "crx.PBX", (voidP) new double(0), ECF::DOUBLE);
00012 }
00013
00014
00015 bool PermutationCrsPBX::initialize(StateP state)
00016 {
00017 voidP sptr = myGenotype_->getParameterValue(state, "crx.PBX");
00018 probability_ = *((double*)sptr.get());
00019 return true;
00020 }
00021
00022
00023 bool PermutationCrsPBX::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
00024 {
00025 Permutation* p1 = (Permutation*) (gen1.get());
00026 Permutation* p2 = (Permutation*) (gen2.get());
00027 Permutation* ch = (Permutation*) (child.get());
00028
00029
00030 std::vector<bool> taged;
00031 taged.resize(p1->getSize());
00032
00033 int count=0;
00034 for(uint i = 0; i < ch->getSize(); i++) {
00035 if(state_->getRandomizer()->getRandomInteger(2) == 0) {
00036 ch->variables[i] = p1->variables[i];
00037 taged[p1->variables[i]] = 1;
00038 count++;
00039 }
00040 else {
00041 ch->variables[i] = -1;
00042 }
00043 }
00044
00045 int indCh = 0;
00046 count = ch->getSize() - count;
00047 for(uint i = 0; i < ch->getSize() && count > 0; i++) {
00048
00049 while(ch->variables[indCh] != -1)
00050 indCh++;
00051
00052 if(taged[p2->variables[i]] != 1) {
00053 ch->variables[indCh] = p2->variables[i];
00054 count--;
00055 }
00056 }
00057 return true;
00058 }
00059
00060 }