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

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

00001 #include "../ECF_base.h"
00002 #include "Permutation.h"
00003 
00004 
00005 namespace Permutation
00006 {
00007 
00008 void PermutationMutInv::registerParameters(StateP state)
00009 {
00010     myGenotype_->registerParameter(state, "mut.inv", (voidP) new double(0), ECF::DOUBLE);
00011 }
00012 
00013 
00014 bool PermutationMutInv::initialize(StateP state)
00015 {
00016     voidP sptr = myGenotype_->getParameterValue(state, "mut.inv");
00017     probability_ = *((double*)sptr.get());
00018     return true;
00019 }
00020 
00021 
00022 bool PermutationMutInv::mutate(GenotypeP gene)
00023 {
00024     Permutation* perm = (Permutation*) (gene.get());
00025 
00026     //najviše možemo uzeti predzandnji element kao početak podniza
00027     int ind1 = state_->getRandomizer()->getRandomInteger(perm->getSize() - 1);
00028     int ind2 = state_->getRandomizer()->getRandomInteger(ind1, perm->getSize() - 1);
00029     int temp = perm->variables[ind2];
00030     int distance = ind2 -ind1 + 1;
00031 
00032     for(int i = 0; i < distance / 2; i++) {
00033         temp = perm->variables[ind1 + i];
00034         perm->variables[ind1 + i] = perm->variables[ind2 - i];
00035         perm->variables[ind2 - i] = temp;
00036     }
00037 
00038     return true;
00039 }
00040 
00041 }

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