ECF 1.5
MutConnection.cpp
1#include "MutConnection.h"
2#include "Cartesian_genotype.h"
3#include "FunctionSet.h"
4namespace cartesian{
6 {
7 myGenotype_->registerParameter(state, "mut.connection", (voidP) new double(0), ECF::DOUBLE);
8 }
9
11 {
12 voidP sptr = myGenotype_->getParameterValue(state, "mut.connection");
13 probability_ = *((double*)sptr.get());
14 return true;
15 }
16
17 bool MutateConnection::mutate(GenotypeP gene)
18 {
19 Cartesian* cartesian = (Cartesian*) gene.get();
20 const std::vector<FunctionP_basic>& vRef = cartesian->functionSet_->vActiveFunctions_;
21 //Connection of which output will be mutated?
22 uint whichOutput = cartesian->get_random_int(0, cartesian->nOutputs - 1);
23 std::vector<uint> trail = cartesian->getActiveTrail(whichOutput);
24 uint whoIsMutated = trail[cartesian->get_random_int(0, trail.size() - 1)];
25 uint rowNumber = cartesian->getRowNumber(whoIsMutated);
26 uint whichConnection = cartesian->get_random_int(0, vRef[cartesian->operator[](whoIsMutated).value]->getNumOfArgs() - 1);
27 uint newConnection = cartesian->randomConnectionGenerator(rowNumber);
28 cartesian->operator[](whoIsMutated).inputConnections[whichConnection] = newConnection;
29 return true;
30 }
31}
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
uint randomConnectionGenerator(uint rowNumber)
Definition: Cartesian.cpp:213
std::vector< uint > getActiveTrail(uint output_number)
Definition: Cartesian.cpp:251
uint nOutputs
number of final outputs
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!
void registerParameters(StateP state)
Register parameters with the system. Called before MutationOp::initialize.