1#include "../ECF_base.h"
3#include "TreeMutPermutation.h"
12 myGenotype_->registerParameter(state,
"mut.permutation", (voidP)
new double(0), ECF::DOUBLE);
18 voidP sptr =
myGenotype_->getParameterValue(state,
"mut.permutation");
32 iNode = state_->getRandomizer()->getRandomInteger((
int) tree->size());
34 }
while((nArgs = tree->at(iNode)->primitive_->getNumberOfArguments()) < 2 && tries < 4);
40 std::vector<uint> permutation;
41 permutation.resize(nArgs);
43 for(uint i = 0; i < nArgs; i++) {
46 uint ind1, ind2, temp;
47 for(uint i = 0; i < nArgs - 1; i++) {
48 ind1 = permutation[i];
49 ind2 = state_->getRandomizer()->getRandomInteger((
int) i, (int) nArgs - 1);
50 temp = permutation[ind1];
51 permutation[ind1] = permutation[ind2];
52 permutation[ind2] = temp;
56 std::vector<uint> offsets;
58 for(uint i = 1; i < nArgs; i++) {
59 offsets.push_back(offsets[i - 1] + tree->at(iNode + offsets[i - 1])->size_);
63 std::vector<NodeP> mutNodes;
64 mutNodes.assign(tree->begin() + iNode, tree->begin() + iNode + tree->at(iNode)->size_);
67 for(uint iArg = 0; iArg < nArgs; iArg++) {
68 uint nNodes = mutNodes[offsets[permutation[iArg]]]->size_;
69 for(uint i = 0; i < nNodes; i++, iCopiedTo++) {
70 tree->at(iNode + iCopiedTo) = mutNodes[offsets[permutation[iArg]] + i];
double probability_
probability of usage of this mutation operator
GenotypeP myGenotype_
pointer to the Genotype that defines this MutationOp
Tree class - implements genotype as a tree.
void registerParameters(StateP)
Register parameters with the system. Called before MutationOp::initialize.
bool mutate(GenotypeP gene)
Performs mutation of a genotype object. The genotype object must be initialized!
bool initialize(StateP)
Initialize mutation operator. Called before first mutation operation.