1#include "../ECF_base.h"
2#include "Permutation.h"
11 myGenotype_->registerParameter(state,
"crx.SPX", (voidP)
new double(0), ECF::DOUBLE);
17 voidP sptr =
myGenotype_->getParameterValue(state,
"crx.SPX");
29 PermutationP ch = boost::static_pointer_cast<Permutation> (child);
32 PermutationP ch2(ch->copy());
34 IndividualP myInd = state_->getContext()->child;
36 uint gId = child->getGenotypeId();
41 int capacity = (int) ch->getSize();
42 for(
int i = 0; i < capacity; i++) {
43 ch->variables[i] = p1->variables[i];
44 ch2->variables[i] = p2->variables[i];
48 int pos1 = state_->getRandomizer()->getRandomInteger(capacity);
49 int pos2 = state_->getRandomizer()->getRandomInteger(capacity);
56 }
else if(pos2<pos1) {
63 int elem1 = p1->variables[pos1];
64 int elem2 = p1->variables[pos2];
65 ch->variables[pos1] = elem2;
66 ch->variables[pos2] = elem1;
69 for(
int i = 0; i < capacity; i++) {
70 if(p2->variables[i]==elem1) {
75 for(
int i = 0; i < capacity; i++) {
76 if(p2->variables[i]==elem2) {
83 ch2->variables[pos1] = elem2;
84 ch2->variables[pos2] = elem1;
86 FitnessP chFitness, ch2Fitness;
88 state_->getAlgorithm()->evaluate(myInd);
89 chFitness = myInd->fitness;
92 myInd->at(gId) = (GenotypeP) ch2;
94 myInd->fitness->setInvalid();
96 state_->getAlgorithm()->evaluate(myInd);
97 ch2Fitness = myInd->fitness;
100 if(chFitness->isBetterThan(ch2Fitness)) {
101 myInd->at(gId) = (GenotypeP) ch;
103 myInd->fitness = chFitness;
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)
Permutation class - implements genotype as a vector of indices 0..(n-1) (permutation of indices)