ECF 1.7
IntGenotypeCrxOp.cpp
1#include "../ECF_base.h"
2#include <cmath>
3#include "IntGenotype.h"
4
5namespace IntGenotype
6{
7
8 bool IntGenotypeCrxOp::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 dimensionCrs = state_->getRandomizer()->getRandomInteger((int)p1->intValues.size());
15 switch (state_->getRandomizer()->getRandomInteger(0, 1)) {
16 case 0: for (uint i = 0; i < dimensionCrs; i++) {
17 ch->intValues[i] = p1->intValues[i];
18 }
19 for (uint i = dimensionCrs; i < p2->intValues.size(); i++) {
20 ch->intValues[i] = p2->intValues[i];
21 }
22 break;
23 case 1: for (uint i = 0; i < dimensionCrs; i++) {
24 ch->intValues[i] = p2->intValues[i];
25 }
26 for (uint i = dimensionCrs; i < p1->intValues.size(); i++) {
27 ch->intValues[i] = p1->intValues[i];
28 }
29 }
30
31 return true;
32 }
33
34}
bool mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
IntGenotype class - implements genotype as a vector of int values.
Definition IntGenotype.h:28