ECF 1.5
CartesianCrsOnePoint.cpp
1#include "CartesianCrsOnePoint.h"
2#include "Cartesian_c.h"
3
4namespace cart{
5
7{
8 //TODO: ako ce se jednog dana koristiti vise operatora
9 //myGenotype_->registerParameter(state, "crx.onepoint", (voidP) new double(0), DOUBLE);
10}
11
12
14{
15 //TODO: ako ce se jednog dana koristiti vise operatora
16 //voidP sptr = myGenotype_->getParameterValue(state, "crx.onepoint");
17 //probability_ = *((double*)sptr.get());
18 return true;
19}
20
21
22bool CartesianCrsOnePoint::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
23{
24 Cartesian* p1 = (Cartesian*) (gen1.get());
25 Cartesian* p2 = (Cartesian*) (gen2.get());
26 Cartesian* ch = (Cartesian*) (child.get());
27
28 //crossing point is any integer value in parents
29 int crsPoint = state_->getRandomizer()->getRandomInteger(p1->size());
30
31 ch->clear();
32 //randomly choose left side of first parent or second parent
33 if ((state_->getRandomizer()->getRandomInteger(0, 1)) == 0)
34 {
35 for (int i = 0; i < crsPoint; i++)
36 {
37 ch->push_back(p1->at(i));
38 }
39 for (int i = crsPoint; i < (int)p2->size(); i++)
40 {
41 ch->push_back(p2->at(i));
42 }
43 }
44 else
45 {
46 for (int i = 0; i < crsPoint; i++)
47 {
48 ch->push_back(p2->at(i));
49 }
50 for (int i = crsPoint; i < (int)p1->size(); i++)
51 {
52 ch->push_back(p1->at(i));
53 }
54 }
55
56 return true;
57}
58
59}
60
bool mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
bool initialize(StateP)
Initialize crossover operator. Called before first crossover operation.
void registerParameters(StateP)
Register parameters with the system. Called before CrossoverOp::initialize.