1#include "../ECF_base.h"
3#include "TreeCrxOnePoint.h"
11 myGenotype_->registerParameter(state,
"crx.onepoint", (voidP)
new double(0), ECF::DOUBLE);
17 voidP sptr =
myGenotype_->getParameterValue(state,
"crx.onepoint");
31 uint mNodeDepth, fNodeDepth, fNodeDepthSize;
33 mRange = (uint) male->size();
34 fRange = (uint) female->size();
37 std::vector <uint> maleCommonRegionIndexes;
38 std::vector <uint> femaleCommonRegionIndexes;
40 for( uint iMale = 0, iFemale = 0; iMale < mRange && iFemale < fRange; iMale++, iFemale++ ) {
42 maleCommonRegionIndexes.push_back( iMale );
43 femaleCommonRegionIndexes.push_back( iFemale );
46 if( male->at( iMale )->primitive_->getNumberOfArguments() != female->at( iFemale )->primitive_->getNumberOfArguments() ) {
47 iMale += male->at( iMale )->size_;
48 iFemale += female->at( iFemale )->size_;
55 uint randomNode = state_->getRandomizer()->getRandomInteger(0 , (
int) maleCommonRegionIndexes.size()-1 );
56 mIndex = maleCommonRegionIndexes[ randomNode ];
57 fIndex = femaleCommonRegionIndexes[ randomNode ];
62 mNodeDepth = male->at( mIndex )->depth_;
63 fNodeDepth = female->at( fIndex )->depth_;
66 uint maxDepth = fNodeDepth, depth;
67 for(uint i = 0; i < female->at( fIndex )->size_; i++) {
68 depth = female->at( fIndex + i )->depth_;
69 maxDepth = depth > maxDepth ? depth : maxDepth;
72 fNodeDepthSize = maxDepth - fNodeDepth;
75 if(nTries > 4 || mNodeDepth + fNodeDepthSize <= male->maxDepth_ )
break;
78 if(nTries > 4 && mNodeDepth + fNodeDepthSize > male->maxDepth_) {
79 ECF_LOG(state_, 5,
"TreeCrxOnePoint not successful.");
84 child->maxDepth_ = male->maxDepth_;
85 child->minDepth_ = male->minDepth_;
86 child->startDepth_ = male->startDepth_;
89 for(uint i = 0; i < mIndex; i++) {
90 NodeP
node =
static_cast<NodeP
> (
new Node( male->at(i)->primitive_));
91 child->push_back(
node );
92 child->at( i )->depth_ = male->at( i )->depth_;
96 for(uint i = 0; i < female->at( fIndex )->size_; i++) {
97 NodeP
node =
static_cast<NodeP
> (
new Node( female->at( fIndex + i)->primitive_));
98 child->push_back(
node );
101 for(uint i = mIndex + male->at( mIndex )->size_; i < mRange; i++) {
102 NodeP
node =
static_cast<NodeP
> (
new Node( male->at( i )->primitive_));
103 child->push_back(
node );
double probability_
probability of usage of this crossover operator
GenotypeP myGenotype_
pointer to the Genotype that defines this CrossoverOp
Node base class (Tree genotype)
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.
Tree class - implements genotype as a tree.