1#include "../ECF_base.h"
2#include "Permutation.h"
11 myGenotype_->registerParameter(state,
"crx.ULX", (voidP)
new double(0), ECF::DOUBLE);
17 voidP sptr =
myGenotype_->getParameterValue(state,
"crx.ULX");
29 std::map<int, int> numCopied;
30 std::vector<int> free;
32 for (
int i = 0; i < (int) p1->getSize(); i++) {
34 if (p1->variables[i] == p2->variables[i]) {
35 ch->variables[i] = p1->variables[i];
36 }
else if (!numCopied[p1->variables[i]] && !numCopied[p2->variables[i]]) {
37 ch->variables[i] = state_->getRandomizer()->getRandomInteger(0, 1) ? p1->variables[i] : p2->variables[i];
38 }
else if (!numCopied[p1->variables[i]]) {
39 ch->variables[i] = p1->variables[i];
40 }
else if (!numCopied[p2->variables[i]]) {
41 ch->variables[i] = p2->variables[i];
47 numCopied[ch->variables[i]] = 1;
50 if (free.size() > 0) {
51 for (
int i = 0; i < (int) p1->getSize(); i++) {
53 int r = state_->getRandomizer()->getRandomInteger((
int) free.size());
55 ch->variables[free[r]] = i;
56 free.erase(free.begin() + r);
58 if (free.size() == 0)
break;
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 mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
bool initialize(StateP)
Initialize crossover operator. Called before first crossover operation.
Permutation class - implements genotype as a vector of indices 0..(n-1) (permutation of indices)