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

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

00001 #include "../ECF_base.h"
00002 #include "Permutation.h"
00003 
00004 
00005 namespace Permutation
00006 {
00007 
00008 void PermutationMutIns::registerParameters(StateP state)
00009 {
00010     myGenotype_->registerParameter(state, "mut.ins", (voidP) new double(0), ECF::DOUBLE);
00011 }
00012 
00013 
00014 bool PermutationMutIns::initialize(StateP state)
00015 {
00016     voidP sptr = myGenotype_->getParameterValue(state, "mut.ins");
00017     probability_ = *((double*)sptr.get());
00018     return true;
00019 }
00020 
00021 
00022 bool PermutationMutIns::mutate(GenotypeP gene)
00023 {
00024     Permutation* perm = (Permutation*) (gene.get());
00025 
00026     //navjeĉi indeks za prvi element insert mutacije
00027     //mora biti maksimalno predzadnji u nizu
00028     int ind1 = state_->getRandomizer()->getRandomInteger(perm->getSize() - 1);
00029     int ind2 = state_->getRandomizer()->getRandomInteger(ind1, perm->getSize() - 1);
00030     int temp = perm->variables[ind2];
00031 
00032     //posmicemo udesno
00033     for(int i = ind2; i > ind1; i--) {
00034         //temp=perm->variables[i];
00035         perm->variables[i] = perm->variables[i - 1];
00036     }
00037     //za slucaj da su indeksi razliciti stavljamo element koji smo prebrisali
00038     //tj zadnji element podniza iza prvog elementa
00039     //inace se for petlja uopce nije izvrsila pa bismo 2x isti element imali
00040     if(ind1 != ind2)
00041         perm->variables[ind1 + 1] = temp;
00042 
00043     return true;
00044 }
00045 
00046 }

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