ECF 1.7
CartesianCrxUniform.cpp
1#include "CartesianCrxUniform.h"
2#include "Cartesian_c.h"
3
4namespace Cartesian {
5
7{
8 myGenotype_->registerParameter(state, "crx.uniform", (voidP) new double(0), ECF::DOUBLE);
9}
10
11
13{
14 voidP sptr = myGenotype_->getParameterValue(state, "crx.uniform");
15 probability_ = *((double*)sptr.get());
16 return true;
17}
18
19
20bool CartesianCrxUniform::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
21{
22 Cartesian* p1 = (Cartesian*) (gen1.get());
23 Cartesian* p2 = (Cartesian*) (gen2.get());
24 Cartesian* ch = (Cartesian*) (child.get());
25
26 // cross function nodes
27 int randomParentChooser;
28 for(uint i = 0; i < p1->nodes_.size(); i++) {
29 randomParentChooser = state_->getRandomizer()->getRandomInteger(0, 1);
30 if (randomParentChooser)
31 ch->nodes_[i] = p1->nodes_[i];
32 else
33 ch->nodes_[i] = p2->nodes_[i];
34 }
35
36 // cross outputs
37 for (uint i = 0; i < p1->nOutputs_; i++) {
38 randomParentChooser = state_->getRandomizer()->getRandomInteger(0, 1);
39 if (randomParentChooser)
40 ch->outputs_[i] = p1->outputs_[i];
41 else
42 ch->outputs_[i] = p2->outputs_[i];
43 }
44
45 return true;
46}
47
48}
49
bool initialize(StateP)
Initialize crossover operator. Called before first crossover operation.
void registerParameters(StateP)
Register parameters with the system. Called before CrossoverOp::initialize.
bool mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
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