ECF 1.5
BitStringCrsUniform.cpp
1#include "../ECF_base.h"
2#include "BitString.h"
3
4namespace BitString
5{
6
8{
9 myGenotype_->registerParameter(state, "crx.uniform", (voidP) new double(0), ECF::DOUBLE);
10}
11
12
14{
15 voidP sptr = myGenotype_->getParameterValue(state, "crx.uniform");
16 probability_ = *((double*)sptr.get());
17 return true;
18}
19
20
21bool BitStringCrsUniform::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
22{
23 BitString* p1 = (BitString*) (gen1.get());
24 BitString* p2 = (BitString*) (gen2.get());
25 BitString* ch = (BitString*) (child.get());
26
27 for(uint i = 0; i < p1->bits.size(); i++){
28 if (p1->bits[i] == p2->bits[i])
29 ch->bits[i] = p1->bits[i];
30 else
31 ch->bits[i] = state_->getRandomizer()->getRandomInteger(2) ? true:false;
32 }
33
34 return true;
35}
36}
bool mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
bool initialize(StateP)
Initialize crossover operator. Called before first crossover operation.
void registerParameters(StateP)
Register parameters with the system. Called before CrossoverOp::initialize.
BitString class - implements genotype as a series of bits.
Definition: BitString.h:24
double probability_
probability of usage of this crossover operator
Definition: Crossover.h:42
GenotypeP myGenotype_
pointer to the Genotype that defines this CrossoverOp
Definition: Crossover.h:43