ECF 1.7
IntGenotypeCrxTwoPoint.cpp
1#include "../ECF_base.h"
2#include <cmath>
3#include "IntGenotype.h"
4
5namespace IntGenotype
6{
7
8 bool IntGenotypeCrxTwoPoint::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child) {
9
10 IntGenotype* p1 = (IntGenotype*)(gen1.get());
11 IntGenotype* p2 = (IntGenotype*)(gen2.get());
12 IntGenotype* ch = (IntGenotype*)(child.get());
13
14 uint dimensionCrs1 = state_->getRandomizer()->getRandomInteger((int)p1->intValues.size());
15 uint dimensionCrs2 = dimensionCrs1, tmp;
16
17 if(p1->intValues.size() > 1)
18 do {
19 dimensionCrs2 = state_->getRandomizer()->getRandomInteger(p1->intValues.size());
20 } while (dimensionCrs1 == dimensionCrs2);
21
22 if (dimensionCrs1 > dimensionCrs2)
23 {
24 tmp = dimensionCrs1;
25 dimensionCrs1 = dimensionCrs2;
26 dimensionCrs2 = tmp;
27 }
28
29 switch (state_->getRandomizer()->getRandomInteger(0, 1)) {
30 case 0: for (uint i = 0; i < dimensionCrs1; i++) {
31 ch->intValues[i] = p1->intValues[i];
32 }
33 for (uint i = dimensionCrs1; i < dimensionCrs2; i++) {
34 ch->intValues[i] = p2->intValues[i];
35 }
36 for (uint i = dimensionCrs2; i < p1->intValues.size(); i++) {
37 ch->intValues[i] = p1->intValues[i];
38 }
39 break;
40 case 1: for (uint i = 0; i < dimensionCrs1; i++) {
41 ch->intValues[i] = p2->intValues[i];
42 }
43 for (uint i = dimensionCrs1; i < dimensionCrs2; i++) {
44 ch->intValues[i] = p1->intValues[i];
45 }
46 for (uint i = dimensionCrs2; i < p2->intValues.size(); i++) {
47 ch->intValues[i] = p2->intValues[i];
48 }
49 }
50
51 return true;
52 }
53
54}
bool mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
IntGenotype class - implements genotype as a vector of int values.
Definition IntGenotype.h:28