ECF 1.5
FloatingPointCrsBlx.cpp
1#include "../ECF_base.h"
2#include "FloatingPoint.h"
3
4
5namespace FloatingPoint
6{
7
9{
10 myGenotype_->registerParameter(state, "crx.blx", (voidP) new double(0), ECF::DOUBLE);
11 myGenotype_->registerParameter(state, "crx.blx.alpha", (voidP) new double(0.5), ECF::DOUBLE);
12}
13
14
16{
17 voidP sptr = myGenotype_->getParameterValue(state, "crx.blx");
18 probability_ = *((double*)sptr.get());
19
20 useAlpha = false;
21 if(myGenotype_->isParameterDefined(state, "crx.blx.alpha"))
22 useAlpha = true;
23
24 sptr = myGenotype_->getParameterValue(state, "crx.blx.alpha");
25 alpha = *((double*)sptr.get());
26
27 return true;
28}
29
30
31bool FloatingPointCrsBlx::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
32{
33 FloatingPoint* p1 = (FloatingPoint*) (gen1.get());
34 FloatingPoint* p2 = (FloatingPoint*) (gen2.get());
35 FloatingPoint* ch = (FloatingPoint*) (child.get());
36
37 double min1, max1, min2, max2, min, max, a, b, I;
38
39 min1 = p1->realValue[0];
40 max1 = p1->realValue[0];
41 min2 = p2->realValue[0];
42 max2 = p2->realValue[0];
43 for (uint i = 1; i < p1->realValue.size(); i++) {
44 if (p1->realValue[i] < min1)
45 min1 = p1->realValue[i];
46 if (p1->realValue[i] > max1)
47 max1 = p1->realValue[i];
48
49 if (p2->realValue[i] < min2)
50 min2 = p2->realValue[i];
51 if (p2->realValue[i] > max2)
52 max2 = p2->realValue[i];
53 }
54 min = (min1 < min2)?min1:min2;
55 max = (max1 > max2)?max1:max2;
56 if(useAlpha)
57 b = alpha;
58 else
59 b = state_->getRandomizer()->getRandomDouble();
60 I = max - min;
61 min = min - I*b;
62 max = max + I*b;
63 for (uint i = 0; i < p1->realValue.size(); i++) {
64 a = state_->getRandomizer()->getRandomDouble();
65 a = min + a*(max-min); // s obzirom da nema tako neceg u SimpleRandomizeru dodao sam ovdje
66 ch->realValue[i] = a;
67 }
68
69 return true;
70}
71
72}
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.
void registerParameters(StateP)
Register parameters with the system. Called before CrossoverOp::initialize.
bool mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
FloatingPoint class - implements genotype as a vector of floating point values.
Definition: FloatingPoint.h:39