1#include "../ECF_base.h"
9 myGenotype_->registerParameter(state,
"mut.mix", (voidP)
new double(0), ECF::DOUBLE);
15 voidP sptr =
myGenotype_->getParameterValue(state,
"mut.mix");
18 sptr =
myGenotype_->getParameterValue(state,
"size");
19 if(*((uint*)sptr.get()) == 1) {
20 ECF_LOG_ERROR(state,
"Warning: mixing mutation not applicable on BitString genotype of size 1!");
30 if(bitstr->bits.size() == 1)
34 uint bitIndexSmaller = state_->getRandomizer()->getRandomInteger((uint) bitstr->bits.size());
38 bitIndexBigger = state_->getRandomizer()->getRandomInteger((uint) bitstr->bits.size());
39 }
while (bitIndexSmaller == bitIndexBigger);
42 uint tmp = bitIndexSmaller;
43 if (bitIndexSmaller > bitIndexBigger) {
44 bitIndexSmaller = bitIndexBigger;
52 for(uint i = bitIndexSmaller; i <= bitIndexBigger; i++) {
53 if(bitstr->bits[i]) counter1++;
57 int fairness0 = counter0;
58 int fairness1 = counter1;
61 for(uint i = bitIndexSmaller; i <= bitIndexBigger; i++) {
62 int random = state_->getRandomizer()->getRandomInteger(1, fairness0 + fairness1);
64 if(random <= fairness1) {
66 bitstr->bits[i] =
true;
70 bitstr->bits[i] =
false;
76 bitstr->bits[i] =
false;
80 bitstr->bits[i] =
true;
BitString class - implements genotype as a series of bits.
void registerParameters(StateP)
Register parameters with the system. Called before MutationOp::initialize.
bool mutate(GenotypeP gene)
Performs mutation of a genotype object. The genotype object must be initialized!
bool initialize(StateP)
Initialize mutation operator. Called before first mutation operation.
double probability_
probability of usage of this mutation operator
GenotypeP myGenotype_
pointer to the Genotype that defines this MutationOp