ECF 1.5
BinaryCrsNonGeometric.cpp
1#include "../ECF_base.h"
2#include "Binary.h"
3
4namespace Binary
5{
6
8{
9 myGenotype_->registerParameter(state, "crx.nongeometric", (voidP) new double(0), ECF::DOUBLE);
10}
11
12
14{
15 voidP sptr = myGenotype_->getParameterValue(state, "crx.nongeometric");
16 probability_ = *((double*)sptr.get());
17
18 return true;
19}
20
21
22/*
23Step 1: Let zi := xi for i =1,2, ...,n (i.e., z is a copy of the
24 primary parent x).
25Step 2: Let zi := (1 - zi) with a probability PBF when xi = yi
26 where PBF is a prespecified bit-flip probability.
27Note: Random primary parent selection
28*/
29bool BinaryCrsNonGeometric::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
30{
31 Binary* p1 = (Binary*) (gen1.get());
32 Binary* p2 = (Binary*) (gen2.get());
33 Binary* ch = (Binary*) (child.get());
34
35 double PBF = 0.5; //prespecified bit-flip probability
36
37 //Step 1
38 for (uint dimension = 0; dimension < p1->variables.size(); dimension++) {
39 switch (state_->getRandomizer()->getRandomInteger(0, 1)) {
40 case 0: for (uint i = 0; i < p1->getNumBits(); i++) {
41 ch->variables[dimension][i] = p1->variables[dimension][i];
42 }
43 break;
44 case 1: for (uint i = 0; i < p2->getNumBits(); i++) {
45 ch->variables[dimension][i] = p2->variables[dimension][i];
46 }
47 }
48 //Step 2
49 for(uint i = 0; i < p1->getNumBits(); i++) {
50 if (p1->variables[dimension][i] == p2->variables[dimension][i]) {
51 double changeProbability = state_->getRandomizer()->getRandomDouble();
52 if (changeProbability > PBF)
53 ch->variables[dimension][i] = ch->variables[dimension][i] ? false:true;
54 }
55 }
56 }
57
58 // update integer and real domain representation
59 ch->update();
60
61 return true;
62}
63
64}
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.
Binary class - implements genotype as a vector of binary coded real values with variable interval and...
Definition: Binary.h:38
std::vector< v_bool > variables
vector of bit vectors
Definition: Binary.h: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