1#include "../ECF_base.h"
3#include "TreeCrxSimple.h"
8 myGenotype_->registerParameter(state,
"crx.simple", (voidP)
new double(0), DOUBLE);
14 voidP sptr =
myGenotype_->getParameterValue(state,
"crx.simple");
23 Tree* male = (Tree*) (gen1.get());
24 Tree* female = (Tree*) (gen2.get());
25 Tree* child = (Tree*) (ch.get());
29 uint mNodeDepth, fNodeDepth, fNodeDepthSize;
30 mRange = (uint) male->size();
31 fRange = (uint) female->size();
36 mIndex = state_->getRandomizer()->getRandomInteger(0 , mRange -1 );
37 fIndex = state_->getRandomizer()->getRandomInteger(0 , fRange -1 );
38 mNodeDepth = male->at( mIndex )->depth_;
39 fNodeDepth = female->at( fIndex )->depth_;
42 int maxDepth = fNodeDepth, depth;
43 for(uint i = 0; i < female->at( fIndex )->size_; i++) {
44 depth = female->at( fIndex + i )->depth_;
45 maxDepth = depth > maxDepth ? depth : maxDepth;
48 fNodeDepthSize = maxDepth - fNodeDepth;
51 if( nTries > 4 || mNodeDepth + fNodeDepthSize <= male->maxDepth_ )
break;
54 if(nTries > 4 && mNodeDepth + fNodeDepthSize > male->maxDepth_) {
55 state_->getLogger()->log(5,
"TreeCrxSimple not successful.");
63 child->maxDepth_ = male->maxDepth_;
64 child->minDepth_ = male->minDepth_;
65 child->startDepth_ = male->startDepth_;
68 for(uint i = 0; i < mIndex; i++) {
69 NodeP
node =
static_cast<NodeP
> (
new Node( male->at(i)->primitive_));
70 child->push_back(
node );
71 child->at( i )->depth_ = male->at( i )->depth_;
74 for(uint i = 0; i < female->at( fIndex )->size_; i++) {
75 NodeP
node =
static_cast<NodeP
> (
new Node( female->at( fIndex + i)->primitive_));
76 child->push_back(
node );
79 for(uint i = mIndex + male->at( mIndex )->size_; i < mRange; i++) {
80 NodeP
node =
static_cast<NodeP
> (
new Node( male->at( i )->primitive_));
81 child->push_back(
node );
double probability_
probability of usage of this crossover operator
GenotypeP myGenotype_
pointer to the Genotype that defines this CrossoverOp
void registerParameters(StateP)
Register parameters with the system. Called before CrossoverOp::initialize.
bool initialize(StateP)
Initialize crossover operator. Called before first crossover operation.
bool mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)