ECF 1.5
FloatingPointCrsBlxAlphaBeta.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.blxalphabeta", (voidP) new double(0), ECF::DOUBLE);
12 state->getRegistry()->registerEntry("alpha", (voidP) new double(0.75), ECF::DOUBLE);
13 state->getRegistry()->registerEntry("beta", (voidP) new double(0.25), ECF::DOUBLE);
14}
15
16
18{
19 voidP sptr = myGenotype_->getParameterValue(state, "crx.blxalphabeta");
20 probability_ = *((double*)sptr.get());
21
22 voidP par = state->getRegistry()->getEntry("alpha");
23 alpha = *((double*) par.get());
24
25 par = state->getRegistry()->getEntry("beta");
26 beta = *((double*) par.get());
27
28 return true;
29}
30
31
32bool FloatingPointCrsBlxAlphaBeta::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
33{
34 FloatingPoint* p1 = (FloatingPoint*) (gen1.get());
35 FloatingPoint* p2 = (FloatingPoint*) (gen2.get());
36 FloatingPoint* ch = (FloatingPoint*) (child.get());
37
38 double min = 0, max = 0, a, I;
39
40 for (uint i = 1; i < p1->realValue.size(); i++) {
41 a = state_->getRandomizer()->getRandomDouble();
42
43 I = fabs(p1->realValue[i] - p2->realValue[i]);
44
45 if (p1->realValue[i] <= p2->realValue[i]){
46 min = p1->realValue[i] - I*alpha;
47 max = p2->realValue[i] + I*beta;
48 }
49 else{
50 min = p2->realValue[i] - I*beta;
51 max = p1->realValue[i] + I*alpha;
52 }
53 ch->realValue[i] = min + a * (max - min);
54 }
55
56 return true;
57}
58
59}
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 initialize(StateP)
Initialize crossover operator. Called before first crossover operation.
bool mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
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