ECF 1.5
FloatingPointCrsArithmetic.cpp
1#include "../ECF_base.h"
2#include "FloatingPoint.h"
3
4namespace FloatingPoint
5{
6
8{
9 myGenotype_->registerParameter(state, "crx.arithmetic", (voidP) new double(0), ECF::DOUBLE);
10}
11
12
14{
15 voidP sptr = myGenotype_->getParameterValue(state, "crx.arithmetic");
16 probability_ = *((double*)sptr.get());
17 return true;
18}
19
20
21bool FloatingPointCrsArithmetic::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
22{
23 FloatingPoint* p1 = (FloatingPoint*) (gen1.get());
24 FloatingPoint* p2 = (FloatingPoint*) (gen2.get());
25 FloatingPoint* ch = (FloatingPoint*) (child.get());
26
27 double a = state_->getRandomizer()->getRandomDouble();
28
29 switch (state_->getRandomizer()->getRandomInteger(0, 1)) {
30 case 0: for (uint i = 0; i < p1->realValue.size(); i++) {
31 ch->realValue[i] = a * (p1->realValue[i]) + (1 - a) * (p2->realValue[i]);
32 }
33 break;
34 case 1: for (uint i = 0; i < p1->realValue.size(); i++) {
35 ch->realValue[i] = a * (p2->realValue[i]) + (1 - a) * (p1->realValue[i]);
36 }
37 }
38
39 return true;
40}
41
42}
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