ECF 1.5
FloatingPointCrsBlxAlpha.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.blxalpha", (voidP) new double(0), ECF::DOUBLE);
12 state->getRegistry()->registerEntry("alpha", (voidP) new double(0.5), ECF::DOUBLE);
13}
14
15
17{
18 voidP sptr = myGenotype_->getParameterValue(state, "crx.blxalpha");
19 probability_ = *((double*)sptr.get());
20
21 voidP par = state->getRegistry()->getEntry("alpha");
22 alpha = *((double*) par.get());
23 return true;
24}
25
26
27bool FloatingPointCrsBlxAlpha::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
28{
29 FloatingPoint* p1 = (FloatingPoint*) (gen1.get());
30 FloatingPoint* p2 = (FloatingPoint*) (gen2.get());
31 FloatingPoint* ch = (FloatingPoint*) (child.get());
32
33 double min, max, a, I, resMin = 0, resMax = 0;
34
35 for (uint i = 1; i < p1->realValue.size(); i++) {
36 a = state_->getRandomizer()->getRandomDouble();
37 if (p1->realValue[i] < p2->realValue[i]){
38 min = p1->realValue[i];
39 }
40 else {
41 min = p2->realValue[i];
42 }
43 if (p1->realValue[i] > p2->realValue[i]){
44 max = p1->realValue[i];
45 }
46 else {
47 max = p2->realValue[i];
48 }
49 I = fabs(max - min);
50 resMin = min - I * alpha;
51 resMax = max + I * alpha;
52 ch->realValue[i] = resMin + a * fabs(resMax - resMin);
53 }
54
55 return true;
56}
57
58}
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
void registerParameters(StateP)
Register parameters with the system. Called before CrossoverOp::initialize.
bool initialize(StateP)
Initialize crossover operator. Called before first crossover operation.
bool mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
FloatingPoint class - implements genotype as a vector of floating point values.
Definition: FloatingPoint.h:39