ECF 1.5
IntGenotypeCrxOp.cpp
1#include <ecf/ECF.h>
2#include <ecf/ECF_base.h>
3#include <cmath>
4#include <sstream>
5#include "IntGenotype.h"
6
7namespace IntGenotype
8{
9
10 bool IntGenotypeCrxOp::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child) {
11
12 IntGenotype* p1 = (IntGenotype*)(gen1.get());
13 IntGenotype* p2 = (IntGenotype*)(gen2.get());
14 IntGenotype* ch = (IntGenotype*)(child.get());
15
16 //uint prva = (int) p1->getUBound();
17 //uint druga = (int) p2->getUBound();
18 //
19 //for (uint i = 0; i < p1->intValues.size(); i++) {
20 // if (p1->intValues[i] < prva)
21 // prva = p1->intValues[i];
22 // if (p2->intValues[i] < druga)
23 // druga = p2->intValues[i];
24 //}
25
26 //for (uint i = 0; i < p1->intValues.size(); i++) {
27 // p1->intValues[i] = p1->intValues[i] - prva;
28 // p2->intValues[i] = p2->intValues[i] - druga;
29 //}
30
31 uint dimensionCrs = state_->getRandomizer()->getRandomInteger((int)p1->intValues.size());
32 switch (state_->getRandomizer()->getRandomInteger(0, 1)) {
33 case 0: for (uint i = 0; i < dimensionCrs; i++) {
34 ch->intValues[i] = p1->intValues[i];
35 }
36 for (uint i = dimensionCrs; i < p2->intValues.size(); i++) {
37 ch->intValues[i] = p2->intValues[i];
38 }
39 break;
40 case 1: for (uint i = 0; i < dimensionCrs; i++) {
41 ch->intValues[i] = p2->intValues[i];
42 }
43 for (uint i = dimensionCrs; i < p1->intValues.size(); i++) {
44 ch->intValues[i] = p1->intValues[i];
45 }
46 }
47
48 return true;
49 }
50
51}
bool mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)