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

D:/Projekt/ECF_trunk/ECF/permutation/PermutationCrsOX2.cpp

00001 #include "../ECF_base.h"
00002 #include "Permutation.h"
00003 #include <map>
00004 
00005 
00006 namespace Permutation
00007 {
00008 
00009 void PermutationCrsOX2::registerParameters(StateP state)
00010 {
00011     myGenotype_->registerParameter(state, "crx.OX2", (voidP) new double(0), ECF::DOUBLE);
00012 }
00013 
00014 
00015 bool PermutationCrsOX2::initialize(StateP state)
00016 {
00017     voidP sptr = myGenotype_->getParameterValue(state, "crx.OX2");
00018     probability_ = *((double*)sptr.get());
00019     return true;
00020 }
00021 
00022 
00023 bool PermutationCrsOX2::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     int start = state_->getRandomizer()->getRandomInteger(p1->getSize());
00030     int end = state_->getRandomizer()->getRandomInteger(start, p1->getSize() - 1);
00031 
00032     std::map<int, int> subSet;
00033 
00034     int ind1 = state_->getRandomizer()->getRandomInteger(p1->getSize() - 1);
00035     int ind2 = state_->getRandomizer()->getRandomInteger(ind1, p1->getSize() - 1);
00036 
00037     // copy subvector into child
00038     for(int i = ind1; i <= ind2; i++) {
00039         ch->variables[i] = p1->variables[i];
00040         subSet[p1->variables[i]] = 1; //bilo je 0
00041     }
00042     int indexChild = (ind2 + 1) % p1->getSize();
00043     std::map<int, int>::iterator iter = subSet.begin();
00044 
00045     // krecemo od pocetka
00046 
00047     int index = 0;
00048     for (int i = 0; i < (int) p1->getSize(); i++) {  // copy remaining part of second permutation
00049         if (index == ind1) {  // skip already copied part
00050             index = ind2 + 1;
00051         }
00052         if (!subSet[p2->variables[i]]) {
00053             ch->variables[index] = p2->variables[i];
00054             index++;
00055         }
00056     }
00057 
00058     return true;
00059 }
00060 
00061 }

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