ECF 1.5
GEPChromosomeCrsOnePoint.cpp
1#include "GEPChromosomeCrsOnePoint.h"
2namespace GEPChromosome{
4 {
5 myGenotype_->registerParameter(state, "crx.onepoint", (voidP) new double(0), ECF::DOUBLE);
6 }
7
8
10 {
11 voidP sptr = myGenotype_->getParameterValue(state, "crx.onepoint");
12 probability_ = *((double*)sptr.get());
13 return true;
14 }
15
16 bool GEPChromosomeCrsOnePoint::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child){
17 // get the genotype from the parents and the child
18 GEPChromosome* p1 = (GEPChromosome*)(gen1.get());
19 GEPChromosome* p2 = (GEPChromosome*)(gen2.get());
20 GEPChromosome* ch = (GEPChromosome*)(child.get());
21 ch->clear();
22 // select a point on which the crossover operator will be applied
23 uint bitCrs = state_->getRandomizer()->getRandomInteger(0, (int)p1->size() - 1);
24 ECF_LOG(state_, 5, "Performing One-Pt crossover at node (" + uint2str(bitCrs) + ")...");
25 // Copy the nodes from one parent until the crossover point, then the nodes from the other parent until the end
26 switch (state_->getRandomizer()->getRandomInteger(0, 1)) {
27 case 0: for (uint i = 0; i < bitCrs; i++) {
28 ch->push_back(static_cast<Tree::NodeP> (new Tree::Node((p1->at(i)))));
29 }
30 for (uint i = bitCrs; i < p2->size(); i++) {
31 ch->push_back(static_cast<Tree::NodeP> (new Tree::Node((p2->at(i)))));
32 }
33 break;
34 case 1: for (uint i = 0; i < bitCrs; i++) {
35 ch->push_back(static_cast<Tree::NodeP> (new Tree::Node((p2->at(i)))));
36 }
37 for (uint i = bitCrs; i < p1->size(); i++) {
38 ch->push_back(static_cast<Tree::NodeP> (new Tree::Node((p1->at(i)))));
39 }
40 }
41
42 return true;
43 }
44}
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
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.
GEPChromosome class - implements genotype as a Gene Expression Programming chromosome.
Definition: GEPChromosome.h:33
Node base class (Tree genotype)
Definition: Node.h:20