ECF 1.5
FloatingPointCrsArithmeticSingle.cpp
1#include "../ECF_base.h"
2#include "FloatingPoint.h"
3
4
5namespace FloatingPoint
6{
7
9{
10 myGenotype_->registerParameter(state, "crx.arithmeticsingle", (voidP) new double(0), ECF::DOUBLE);
11}
12
13
15{
16 voidP sptr = myGenotype_->getParameterValue(state, "crx.arithmeticsingle");
17 probability_ = *((double*)sptr.get());
18 return true;
19}
20
21
22bool FloatingPointCrsArithmeticSingle::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
23{
24 FloatingPoint* p1 = (FloatingPoint*) (gen1.get());
25 FloatingPoint* p2 = (FloatingPoint*) (gen2.get());
26 FloatingPoint* ch = (FloatingPoint*) (child.get());
27
28 double a = state_->getRandomizer()->getRandomDouble();
29 uint dimensionCrs = state_->getRandomizer()->getRandomInteger((int) p1->realValue.size());
30
31 switch (state_->getRandomizer()->getRandomInteger(0, 1)) {
32 case 0: for (uint i = 0; i < dimensionCrs; i++) {
33 ch->realValue[i] = p1->realValue[i];
34 }
35 ch->realValue[dimensionCrs] = a * (p2->realValue[dimensionCrs]) + (1 - a) * p1->realValue[dimensionCrs];
36 for (uint i = dimensionCrs+1; i < p1->realValue.size(); i++) {
37 ch->realValue[i] = p1->realValue[i];
38 }
39 break;
40 case 1: for (uint i = 0; i < dimensionCrs; i++) {
41 ch->realValue[i] = p2->realValue[i];
42 }
43 ch->realValue[dimensionCrs] = a * (p1->realValue[dimensionCrs]) + (1 - a) * p2->realValue[dimensionCrs];
44 for (uint i = dimensionCrs+1; i < p2->realValue.size(); i++) {
45 ch->realValue[i] = p2->realValue[i];
46 }
47 }
48
49 return true;
50}
51
52}
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
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.
FloatingPoint class - implements genotype as a vector of floating point values.
Definition: FloatingPoint.h:39