1#include "CartesianCrxOnePoint.h"
2#include "Cartesian_genotype.h"
7 myGenotype_->registerParameter(state,
"crx.onepoint", (voidP)
new double(0), ECF::DOUBLE);
12 voidP sptr =
myGenotype_->getParameterValue(state,
"crx.onepoint");
23 uint parent1Size = p1->size() - p1->
nOutputs;
24 uint parent2Size = p2->size() - p2->
nOutputs;
25 uint minimumSize = parent1Size > parent2Size ? parent1Size : parent2Size;
26 bool parent1IsLonger = parent1Size > parent2Size;
28 double whichParent = p1->get_random_double(0,1.0);
29 uint index = p1->get_random_int(0, minimumSize);
30 if(whichParent < 0.5) {
31 for(uint i = 0; i < index; i++) {
32 ch->push_back(p1->operator[](i));
34 for(uint i = index; i < minimumSize; i++) {
35 ch->push_back(p2->operator[](i));
39 for(uint i = 0; i < index; i++) {
40 ch->push_back(p2->operator[](i));
42 for(uint i = index; i < minimumSize; i++) {
43 ch->push_back(p1->operator[](i));
47 for(uint i = parent2Size; i < parent1Size; i++) {
48 ch->push_back(p1->operator[](i));
52 for(uint i = parent1Size; i < parent2Size; i++) {
53 ch->push_back(p1->operator[](i));
56 for(uint i = 0; i < p1->
nOutputs; i++) {
57 if(whichParent < 0.5) {
58 ch->push_back(p1->operator[](parent1Size + i));
61 ch->push_back(p1->operator[](parent2Size + i));
double probability_
probability of usage of this crossover operator
GenotypeP myGenotype_
pointer to the Genotype that defines this CrossoverOp
bool initialize(StateP state)
Initialize crossover operator. Called before first crossover operation.
void registerParameters(StateP state)
Register parameters with the system. Called before CrossoverOp::initialize.
bool mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
uint nOutputs
number of final outputs