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
17 for (uint i = 0; i < p1->intValues.size(); i++) {
18 double a = state_->getRandomizer()->getRandomDouble(); // [0,1]
19 if (a < 0.5) {
20 ch->intValues[i] = p1->intValues[i];
21 }
22 else {
23 ch->intValues[i] = p2->intValues[i];
24 }
25 }
26
27 return true;
28 }
29
30}
bool mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)