ECF 1.5
PermutationMutIns.cpp
1#include "../ECF_base.h"
2#include "Permutation.h"
3
4
5namespace Permutation
6{
7
9{
10 myGenotype_->registerParameter(state, "mut.ins", (voidP) new double(0), ECF::DOUBLE);
11}
12
13
15{
16 voidP sptr = myGenotype_->getParameterValue(state, "mut.ins");
17 probability_ = *((double*)sptr.get());
18 return true;
19}
20
21
22bool PermutationMutIns::mutate(GenotypeP gene)
23{
24 Permutation* perm = (Permutation*) (gene.get());
25
26 //navjeĉi indeks za prvi element insert mutacije
27 //mora biti maksimalno predzadnji u nizu
28 int ind1 = state_->getRandomizer()->getRandomInteger(perm->getSize() - 1);
29 int ind2 = state_->getRandomizer()->getRandomInteger(ind1, (int) perm->getSize() - 1);
30 int temp = perm->variables[ind2];
31
32 //posmicemo udesno
33 for(int i = ind2; i > ind1; i--) {
34 //temp=perm->variables[i];
35 perm->variables[i] = perm->variables[i - 1];
36 }
37 //za slucaj da su indeksi razliciti stavljamo element koji smo prebrisali
38 //tj zadnji element podniza iza prvog elementa
39 //inace se for petlja uopce nije izvrsila pa bismo 2x isti element imali
40 if(ind1 != ind2)
41 perm->variables[ind1 + 1] = temp;
42
43 return true;
44}
45
46}
double probability_
probability of usage of this mutation operator
Definition: Mutation.h:40
GenotypeP myGenotype_
pointer to the Genotype that defines this MutationOp
Definition: Mutation.h:41
Permutation class - implements genotype as a vector of indices 0..(n-1) (permutation of indices)
Definition: Permutation.h:37
bool mutate(GenotypeP gene)
Performs mutation of a genotype object. The genotype object must be initialized!
void registerParameters(StateP)
Register parameters with the system. Called before MutationOp::initialize.
bool initialize(StateP)
Initialize mutation operator. Called before first mutation operation.