ECF 1.5
FloatingPointCrsFlat.cpp
1#include "../ECF_base.h"
2#include "FloatingPoint.h"
3#include<cmath>
4
5
6namespace FloatingPoint
7{
8
10{
11 myGenotype_->registerParameter(state, "crx.flat", (voidP) new double(0), ECF::DOUBLE);
12}
13
14
16{
17 voidP sptr = myGenotype_->getParameterValue(state, "crx.flat");
18 probability_ = *((double*)sptr.get());
19
20 return true;
21}
22
23
24bool FloatingPointCrsFlat::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
25{
26 FloatingPoint* p1 = (FloatingPoint*) (gen1.get());
27 FloatingPoint* p2 = (FloatingPoint*) (gen2.get());
28 FloatingPoint* ch = (FloatingPoint*) (child.get());
29
30 double min, max, a, I;
31
32 for (uint i = 1; i < p1->realValue.size(); i++) {
33 a = state_->getRandomizer()->getRandomDouble();
34 if (p1->realValue[i] < p2->realValue[i]){
35 min = p1->realValue[i];
36 }
37 else {
38 min = p2->realValue[i];
39 }
40 if (p1->realValue[i] > p2->realValue[i]){
41 max = p1->realValue[i];
42 }
43 else {
44 max = p2->realValue[i];
45 }
46 I = fabs(max - min);
47 ch->realValue[i] = min + a * fabs(max - min);
48 }
49
50 return true;
51}
52
53}
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