1#include "../ECF_base.h"
3#include "TreeCrxSizeFair.h"
11 myGenotype_->registerParameter(state,
"crx.sizefair", (voidP)
new double(0), ECF::DOUBLE);
17 voidP sptr =
myGenotype_->getParameterValue(state,
"crx.sizefair");
23int TreeCrxSizeFair::calculateSize (
int avg)
26 return avg + state_->getRandomizer()->getRandomInteger(-sigma , sigma);
38 uint mNodeDepth, fNodeDepth, fNodeDepthSize;
40 mRange = (uint) male->size();
41 fRange = (uint) female->size();
44 std::vector < std::vector<uint> > femaleSizeIndexes;
46 femaleSizeIndexes.resize( fRange + 1 );
48 for(uint i = 0; i < fRange; i++)
49 femaleSizeIndexes[ female->at( i )->size_ ].push_back( i );
54 mIndex = state_->getRandomizer()->getRandomInteger(0 , (
int) mRange -1 );
57 uint subtreeSize = calculateSize ((
int) male->at( mIndex )->size_);
60 if( subtreeSize <= fRange && femaleSizeIndexes[ subtreeSize ].size())
break;
63 uint tmpRnd = state_->getRandomizer()->getRandomInteger(0 , (
int) femaleSizeIndexes[ subtreeSize ].size() - 1 );
64 fIndex = femaleSizeIndexes[ subtreeSize ][ tmpRnd ];
66 mNodeDepth = male->at( mIndex )->depth_;
67 fNodeDepth = female->at( fIndex )->depth_;
70 uint maxDepth = fNodeDepth, depth;
71 for(uint i = 0; i < female->at( fIndex )->size_; i++) {
72 depth = female->at( fIndex + i )->depth_;
73 maxDepth = depth > maxDepth ? depth : maxDepth;
76 fNodeDepthSize = maxDepth - fNodeDepth;
79 if(nTries > 4 || mNodeDepth + fNodeDepthSize <= male->maxDepth_ )
break;
82 if(nTries > 4 && mNodeDepth + fNodeDepthSize > male->maxDepth_) {
83 ECF_LOG(state_, 5,
"TreeCrxSizeFair not successful.");
88 child->maxDepth_ = male->maxDepth_;
89 child->minDepth_ = male->minDepth_;
90 child->startDepth_ = male->startDepth_;
93 for(uint i = 0; i < mIndex; i++) {
94 NodeP
node =
static_cast<NodeP
> (
new Node( male->at(i)->primitive_));
95 child->push_back(
node );
96 child->at( i )->depth_ = male->at( i )->depth_;
100 for(uint i = 0; i < female->at( fIndex )->size_; i++) {
101 NodeP
node =
static_cast<NodeP
> (
new Node( female->at( fIndex + i)->primitive_));
102 child->push_back(
node );
105 for(uint i = mIndex + male->at( mIndex )->size_; i < mRange; i++) {
106 NodeP
node =
static_cast<NodeP
> (
new Node( male->at( i )->primitive_));
107 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 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)
Tree class - implements genotype as a tree.