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