1#include "MutFunction.h"
2#include "Cartesian_genotype.h"
3#include "FunctionSet.h"
8 myGenotype_->registerParameter(state,
"mut.func", (voidP)
new double(0), ECF::DOUBLE);
13 voidP sptr =
myGenotype_->getParameterValue(state,
"mut.func");
21 const std::vector<FunctionP_basic>& vRef = cartesian->functionSet_->vActiveFunctions_;
24 uint whichOutput = cartesian->get_random_int(0, cartesian->
nOutputs - 1);
26 uint whoIsMutated = trail[cartesian->get_random_int(0, trail.size() - 1)];
27 uint oldFunctionId = cartesian->operator[](whoIsMutated).value;
28 uint oldNumOfArgs = vRef[oldFunctionId]->getNumOfArgs();
30 uint newFunctionId = cartesian->get_random_int(0, vRef.size() - 1);
31 while(newFunctionId == oldFunctionId) {
32 newFunctionId = cartesian->get_random_int(0, vRef.size() - 1);
34 uint newNumOfArgs = vRef[newFunctionId]->getNumOfArgs();
37 cartesian->operator[](whoIsMutated).value = newFunctionId;
40 if(oldNumOfArgs < newNumOfArgs){
41 uint rowNumber = cartesian->getRowNumber(whoIsMutated);
42 while(oldNumOfArgs < newNumOfArgs) {
44 cartesian->operator[](whoIsMutated).inputConnections.push_back(connection);
48 else if(oldNumOfArgs > newNumOfArgs) {
49 while(oldNumOfArgs > newNumOfArgs) {
50 uint connection = cartesian->get_random_int(0, oldNumOfArgs - 1);
51 cartesian->operator[](whoIsMutated).inputConnections.erase(cartesian->operator[](whoIsMutated).inputConnections.begin() + connection);
double probability_
probability of usage of this mutation operator
GenotypeP myGenotype_
pointer to the Genotype that defines this MutationOp
uint randomConnectionGenerator(uint rowNumber)
std::vector< uint > getActiveTrail(uint output_number)
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.