ECF 1.5
GEPChromosomeMutOp.cpp
1#include "GEPChromosomeMutOp.h"
2namespace GEPChromosome{
4 {
5 myGenotype_->registerParameter(state, "mut.simple", (voidP) new double(0), ECF::DOUBLE);
6 }
7
8
10 {
11 voidP sptr = myGenotype_->getParameterValue(state, "mut.simple");
12 probability_ = *((double*)sptr.get());
13
14 return true;
15 }
16 bool GEPChromosomeMutOp::mutate(GenotypeP gene){
17 GEPChromosome* chr = (GEPChromosome*)(gene.get());
18 // mutate a single random point in the genotype by selecting a random primitive
19 // Select a random gene
20 uint iGene = state_->getRandomizer()->getRandomInteger(0, chr->genes - 1);
21 uint geneOffset = iGene * chr->geneLength;
22 // Select a random point in the head+tail
23 uint iPoint = state_->getRandomizer()->getRandomInteger(0, (uint)(chr->headLength+chr->tailLength) - 1);
24 std::stringstream logstr;
25 logstr << "Mutating node (" << iPoint << ") in gene [" << iGene << "]...";
26 ECF_LOG(state_, 5, logstr.str());
27 // get primitive depending on where the selected point is
28 // head points can change into anything; tail points must be terminals
29 chr->at(geneOffset + iPoint)->setPrimitive(iPoint < chr->headLength ? chr->primitiveSet_->getRandomPrimitive() : chr->primitiveSet_->getRandomTerminal());
30 return true;
31 }
32}
GEPChromosome class - implements genotype as a Gene Expression Programming chromosome.
Definition: GEPChromosome.h:33
bool mutate(GenotypeP gene)
Performs mutation of a genotype object. The genotype object must be initialized!
void registerParameters(StateP state)
Register parameters with the system. Called before MutationOp::initialize.
bool initialize(StateP state)
Initialize mutation operator. Called before first mutation operation.
double probability_
probability of usage of this mutation operator
Definition: Mutation.h:40
GenotypeP myGenotype_
pointer to the Genotype that defines this MutationOp
Definition: Mutation.h:41