ECF 1.5
PermutationMutToggle.cpp
1#include "../ECF_base.h"
2#include "Permutation.h"
3
4
5namespace Permutation
6{
7
9{
10 myGenotype_->registerParameter(state, "mut.toggle", (voidP) new double(0), ECF::DOUBLE);
11}
12
13
15{
16 voidP sptr = myGenotype_->getParameterValue(state, "mut.toggle");
17 probability_ = *((double*)sptr.get());
18 return true;
19}
20
21
22bool PermutationMutToggle::mutate(GenotypeP gene)
23{
24 Permutation* perm = (Permutation*) (gene.get());
25
26 int ind1 = state_->getRandomizer()->getRandomInteger(perm->getSize());
27 int ind2 = state_->getRandomizer()->getRandomInteger(perm->getSize());
28 int temp = perm->variables[ind1];
29 perm->variables[ind1] = perm->variables[ind2];
30 perm->variables[ind2] = temp;
31
32 return true;
33}
34
35}
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
void registerParameters(StateP)
Register parameters with the system. Called before MutationOp::initialize.
bool initialize(StateP)
Initialize mutation operator. Called before first mutation operation.
bool mutate(GenotypeP gene)
Performs mutation of a genotype object. The genotype object must be initialized!