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

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

00001 #include "../ECF_base.h"
00002 #include "Permutation.h"
00003 #include <map>
00004 
00005 
00006 namespace Permutation
00007 {
00008 
00009 void PermutationCrsCyclic2::registerParameters(StateP state)
00010 {
00011     myGenotype_->registerParameter(state, "crx.cyclic2", (voidP) new double(0), ECF::DOUBLE);
00012 }
00013 
00014 
00015 bool PermutationCrsCyclic2::initialize(StateP state)
00016 {
00017     voidP sptr = myGenotype_->getParameterValue(state, "crx.cyclic2");
00018     probability_ = *((double*)sptr.get());
00019     return true;
00020 }
00021 
00022 
00023 bool PermutationCrsCyclic2::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::map<int, int>  index;
00031     int j, num;
00032 
00033     j = state_->getRandomizer()->getRandomInteger(p1->getSize());
00034 
00035     while (!index[j]) { //da li je ovo OK?
00036         ch->variables[j] = p1->variables[j];
00037         num = p2->variables[j];
00038         index[j] = 1;
00039 
00040         j = 0;
00041         while ((j < (int) p1->getSize()) && (p1->variables[j] != num)) {
00042           j++;
00043         }
00044     }
00045 
00046       for (int i = 0; i < (int) p1->getSize(); i++) {
00047         if (!index[i]) {
00048             ch->variables[i] = p2->variables[i];
00049         }
00050       }
00051 
00052     return true;
00053 }
00054 
00055 }

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