1#include "CartesianCrxHalfUniform.h"
2#include "Cartesian_genotype.h"
7 myGenotype_->registerParameter(state,
"crx.halfuniform", (voidP)
new double(0), ECF::DOUBLE);
12 voidP sptr =
myGenotype_->getParameterValue(state,
"crx.halfuniform");
23 uint parent1Size = p1->size() - p1->
nOutputs;
24 uint parent2Size = p2->size() - p2->
nOutputs;
25 uint minimumSize = parent1Size > parent2Size ? parent1Size : parent2Size;
26 bool parent1IsLonger = parent1Size > parent2Size;
29 double whichParent = p1->get_random_double(0,1);
30 double whichPart = p1->get_random_double(0,1);
31 uint crossoverStart = 0;
32 uint crossoverEnd = minimumSize/2;
33 uint start = crossoverEnd;
34 uint end = minimumSize;
35 bool keepFirst =
false;
36 if(whichPart >= 0.5) {
40 crossoverEnd = minimumSize;
43 if(whichParent < 0.5) {
45 for(uint i = start; i < end; i++){
46 ch->push_back(p1->operator[](i));
48 for(uint i = crossoverStart; i < crossoverEnd; i++) {
49 double randomResult = p1->get_random_double(0,1);
50 if(randomResult < 0.5) {
51 ch->push_back(p1->operator[](i));
54 ch->push_back(p2->operator[](i));
59 for(uint i = crossoverStart; i < crossoverEnd; i++) {
60 double randomResult = p1->get_random_double(0,1);
61 if(randomResult < 0.5) {
62 ch->push_back(p1->operator[](i));
65 ch->push_back(p2->operator[](i));
68 for(uint i = start; i < end; i++){
69 ch->push_back(p1->operator[](i));
75 for(uint i = start; i < end; i++){
76 ch->push_back(p2->operator[](i));
78 for(uint i = crossoverStart; i < crossoverEnd; i++) {
79 double randomResult = p1->get_random_double(0,1);
80 if(randomResult < 0.5) {
81 ch->push_back(p1->operator[](i));
84 ch->push_back(p2->operator[](i));
89 for(uint i = crossoverStart; i < crossoverEnd; i++) {
90 double randomResult = p1->get_random_double(0,1);
91 if(randomResult < 0.5) {
92 ch->push_back(p1->operator[](i));
95 ch->push_back(p2->operator[](i));
98 for(uint i = start; i < end; i++){
99 ch->push_back(p2->operator[](i));
103 if(parent1IsLonger) {
104 for(uint i = parent2Size; i < parent1Size; i++) {
105 ch->push_back(p1->operator[](i));
109 for(uint i = parent1Size; i < parent2Size; i++) {
110 ch->push_back(p1->operator[](i));
114 for(uint i = 0; i < p1->
nOutputs; i++) {
115 if(whichParent < 0.5) {
116 ch->push_back(p1->operator[](parent1Size + i));
119 ch->push_back(p1->operator[](parent2Size + i));
double probability_
probability of usage of this crossover operator
GenotypeP myGenotype_
pointer to the Genotype that defines this CrossoverOp
uint nOutputs
number of final outputs