ECF 1.7
CartesianCrxOnePoint.cpp
1#include "CartesianCrxOnePoint.h"
2#include "Cartesian_c.h"
3#include "FunctionSet.h"
4
5namespace Cartesian {
6
8 {
9 myGenotype_->registerParameter(state, "crx.onepoint", (voidP) new double(0), ECF::DOUBLE);
10 }
11
12
14 {
15 voidP sptr = myGenotype_->getParameterValue(state, "crx.onepoint");
16 probability_ = *((double*)sptr.get());
17 return true;
18 }
19
20
21 bool CartesianCrxOnePoint::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
22 {
23 Cartesian* p1 = (Cartesian*) (gen1.get());
24 Cartesian* p2 = (Cartesian*) (gen2.get());
25 Cartesian* ch = (Cartesian*) (child.get());
26
27 uint nNodes = (uint) p1->nodes_.size() - p1->nInputs_;
28
29 if (nNodes < 2) {
30 // copy all from 1st parent
31 ch->nodes_ = p1->nodes_;
32 ch->outputs_ = p1->outputs_;
33 return true;
34 }
35
36 uint cutoff = p1->nInputs_ + state_->getRandomizer()->getRandomInteger(1, nNodes - 1);
37
38 for(uint i = 0; i < cutoff; i++) {
39 ch->nodes_[i] = p1->nodes_[i];
40 }
41 for(uint i = cutoff; i < p2->nodes_.size(); i++) {
42 ch->nodes_[i] = p2->nodes_[i];
43 }
44 // output nodes taken from the 2nd parent
45 for (uint i = 0; i < p2->outputs_.size(); i++)
46 ch->outputs_[i] = p2->outputs_[i];
47
48 return true;
49 }
50
51}
bool mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
void registerParameters(StateP)
Register parameters with the system. Called before CrossoverOp::initialize.
bool initialize(StateP)
Initialize crossover operator. Called before first crossover operation.
double probability_
probability of usage of this crossover operator
Definition Crossover.h:42
GenotypeP myGenotype_
pointer to the Genotype that defines this CrossoverOp
Definition Crossover.h:43