ECF 1.5
BitStringCrsOnePoint.cpp
1#include "../ECF_base.h"
2#include "BitString.h"
3
4namespace BitString
5{
6
8{
9 myGenotype_->registerParameter(state, "crx.onepoint", (voidP) new double(0), ECF::DOUBLE);
10}
11
12
14{
15 voidP sptr = myGenotype_->getParameterValue(state, "crx.onepoint");
16 probability_ = *((double*)sptr.get());
17 return true;
18}
19
20
21bool BitStringCrsOnePoint::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 uint bitCrs = state_->getRandomizer()->getRandomInteger(0, (int) p1->bits.size() - 1);
28
29 switch (state_->getRandomizer()->getRandomInteger(0, 1)) {
30 case 0: for (uint i=0; i < bitCrs; i++) {
31 ch->bits[i] = p1->bits.at(i);
32 }
33 for (uint i=bitCrs; i < p2->bits.size(); i++) {
34 ch->bits[i] = p2->bits.at(i);
35 }
36 break;
37 case 1: for (uint i=0; i < bitCrs; i++) {
38 ch->bits[i] = p2->bits.at(i);
39 }
40 for (uint i=bitCrs; i < p1->bits.size(); i++) {
41 ch->bits[i] = p1->bits.at(i);
42 }
43 }
44
45 return true;
46}
47
48}
bool mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
void registerParameters(StateP)
Register parameters with the system. Called before CrossoverOp::initialize.
bool initialize(StateP)
Initialize crossover operator. Called before first crossover operation.
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