1#include "../ECF_base.h"
3#include "TreeCrxContextPreserved.h"
12 myGenotype_->registerParameter(state,
"crx.context", (voidP)
new double(0), ECF::DOUBLE);
18 voidP sptr =
myGenotype_->getParameterValue(state,
"crx.context");
32 mRange = (uint) male->size();
33 fRange = (uint) female->size();
36 std::vector <uint> maleCommonIndexes;
37 std::vector <uint> femaleCommonIndexes;
40 std::stack <uint> maleSkip;
41 std::stack <uint> femaleSkip;
43 for(uint iMale = 0, iFemale = 0; iMale < mRange && iFemale < fRange; iMale++, iFemale++) {
45 while (!maleSkip.empty() && iMale == maleSkip.top()) {
47 iMale += male->at(iMale)->size_;
49 if (iMale >= mRange)
break;
52 while (!femaleSkip.empty() && iFemale == femaleSkip.top()) {
54 iFemale += female->at(iFemale)->size_;
56 if (iFemale >= fRange)
break;
59 maleCommonIndexes.push_back(iMale);
60 femaleCommonIndexes.push_back(iFemale);
62 uint maleArgNum = male->at(iMale)->primitive_->getNumberOfArguments();
63 uint femaleArgNum = female->at(iFemale)->primitive_->getNumberOfArguments();
65 if (maleArgNum > femaleArgNum) {
67 std::vector<uint> toSkip;
69 uint tmpIndex = iMale + 1;
70 for(uint i = 0; i < maleArgNum; i++) {
71 if (i >= femaleArgNum) toSkip.push_back(tmpIndex);
72 tmpIndex += male->at(tmpIndex)->size_;
75 for(
int i = (
int) toSkip.size() - 1; i >= 0; i--)
76 maleSkip.push(toSkip[i]);
78 if (maleArgNum < femaleArgNum) {
80 std::vector<uint> toSkip;
82 uint tmpIndex = iFemale + 1;
83 for(uint i = 0; i < femaleArgNum; i++) {
84 if (i >= maleArgNum) toSkip.push_back(tmpIndex);
85 tmpIndex += female->at(tmpIndex)->size_;
88 for(
int i = (
int) toSkip.size() - 1; i >= 0; i--)
89 femaleSkip.push(toSkip[i]);
93 if(maleCommonIndexes.empty()) {
94 ECF_LOG(state_, 5,
"TreeCrxContextPreserved not successful.");
98 uint rndIndex = state_->getRandomizer()->getRandomInteger((uint)maleCommonIndexes.size());
100 mIndex = maleCommonIndexes[ rndIndex ];
101 fIndex = femaleCommonIndexes[ rndIndex ];
106 child->maxDepth_= male->maxDepth_;
107 child->minDepth_ = male->minDepth_;
108 child->startDepth_ = male->startDepth_;
111 for(uint i = 0; i < mIndex; i++) {
112 NodeP
node =
static_cast<NodeP
> (
new Node(male->at(i)->primitive_));
113 child->push_back(
node);
114 child->at(i)->depth_ = male->at(i)->depth_;
117 for(uint i = 0; i < female->at( fIndex )->size_; i++) {
118 NodeP
node =
static_cast<NodeP
> (
new Node(female->at( fIndex + i)->primitive_));
119 child->push_back(
node);
122 for(uint i = mIndex + male->at( mIndex )->size_; i < mRange; i++) {
123 NodeP
node =
static_cast<NodeP
> (
new Node( male->at(i)->primitive_));
124 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)
bool initialize(StateP)
Initialize crossover operator. Called before first crossover operation.
void registerParameters(StateP)
Register parameters with the system. Called before CrossoverOp::initialize.
Tree class - implements genotype as a tree.