ECF 1.5
IntGenotypeCrxTwoPoint.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 IntGenotypeCrxTwoPoint::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 //int prva = (int) p1->getUBound();
17 //int 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 dimensionCrs1 = state_->getRandomizer()->getRandomInteger((int)p1->intValues.size());
32 uint dimensionCrs2, tmp;
33
34 do
35 {
36 dimensionCrs2 = state_->getRandomizer()->getRandomInteger(p1->intValues.size());
37 } while (dimensionCrs1 == dimensionCrs2);
38
39 if (dimensionCrs1 > dimensionCrs2)
40 {
41 tmp = dimensionCrs1;
42 dimensionCrs1 = dimensionCrs2;
43 dimensionCrs2 = tmp;
44 }
45
46 switch (state_->getRandomizer()->getRandomInteger(0, 1)) {
47 case 0: for (uint i = 0; i < dimensionCrs1; i++) {
48 ch->intValues[i] = p1->intValues[i];
49 }
50 for (uint i = dimensionCrs1; i < dimensionCrs2; i++) {
51 ch->intValues[i] = p2->intValues[i];
52 }
53 for (uint i = dimensionCrs2; i < p1->intValues.size(); i++) {
54 ch->intValues[i] = p1->intValues[i];
55 }
56 break;
57 case 1: for (uint i = 0; i < dimensionCrs1; i++) {
58 ch->intValues[i] = p2->intValues[i];
59 }
60 for (uint i = dimensionCrs1; i < dimensionCrs2; i++) {
61 ch->intValues[i] = p1->intValues[i];
62 }
63 for (uint i = dimensionCrs2; i < p2->intValues.size(); i++) {
64 ch->intValues[i] = p2->intValues[i];
65 }
66 }
67
68 return true;
69 }
70
71}
bool mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)