ECF 1.7
GEPChromosomeMutOp.cpp
1#include "GEPChromosomeMutOp.h"
2
3namespace GEP{
5 {
6 myGenotype_->registerParameter(state, "mut.simple", (voidP) new double(0), ECF::DOUBLE);
7 }
8
9
11 {
12 voidP sptr = myGenotype_->getParameterValue(state, "mut.simple");
13 probability_ = *((double*)sptr.get());
14
15 return true;
16 }
17 bool GEPChromosomeMutOp::mutate(GenotypeP gene){
18 GEPChromosome* chr = (GEPChromosome*)(gene.get());
19 // mutate a single random point in the genotype by selecting a random primitive
20 // Select a random gene
21 uint iGene = state_->getRandomizer()->getRandomInteger(0, chr->genes - 1);
22 uint geneOffset = iGene * chr->geneLength;
23 // Select a random point in the head+tail
24 uint iPoint = state_->getRandomizer()->getRandomInteger(0, (uint)(chr->headLength+chr->tailLength) - 1);
25 std::stringstream logstr;
26 logstr << "Mutating node (" << iPoint << ") in gene [" << iGene << "]...";
27 ECF_LOG(state_, 5, logstr.str());
28 // get primitive depending on where the selected point is
29 // head points can change into anything; tail points must be terminals
30 chr->at(geneOffset + iPoint)->setPrimitive(iPoint < chr->headLength ? chr->primitiveSet_->getRandomPrimitive() : chr->primitiveSet_->getRandomTerminal());
31 return true;
32 }
33}
GEPChromosome class - implements genotype as a Gene Expression Programming chromosome.
uint genes
number of genes
uint tailLength
length of the tail. Automatically calculated.
uint geneLength
total length of each gene
uint headLength
length of the head. User-specified
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.
bool mutate(GenotypeP gene)
Performs mutation of a genotype object. The genotype object must be initialized!
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