2#include "MutFunctionSilent.h"
3#include "Cartesian_genotype.h"
4#include "FunctionSet.h"
9 myGenotype_->registerParameter(state,
"mut.funcsilent", (voidP)
new double(0), ECF::DOUBLE);
14 voidP sptr =
myGenotype_->getParameterValue(state,
"mut.funcsilent");
22 const std::vector<FunctionP_basic>& vRef = cartesian->functionSet_->vActiveFunctions_;
23 std::set<uint> allActiveIndexes;
24 std::vector<std::vector<uint> > allTrails = cartesian->
getActiveTrails();
25 for(uint i = 0; i < allTrails.size(); i++) {
26 for(uint j = 0; j < allTrails[i].size(); j++) {
27 allActiveIndexes.insert(allTrails[i][j]);
30 uint toBeMutated = cartesian->get_random_int(0, cartesian->size() - 1 -cartesian->
nOutputs);
31 if(allActiveIndexes.size() == cartesian->size() - cartesian->
nOutputs) {
34 while(allActiveIndexes.count(toBeMutated)) {
35 toBeMutated = cartesian->get_random_int(0, cartesian->size() - 1 -cartesian->
nOutputs);
37 uint oldFunctionId = cartesian->operator[](toBeMutated).value;
38 uint oldNumOfArgs = vRef[oldFunctionId]->getNumOfArgs();
39 uint newFunctionId = cartesian->get_random_int(0, vRef.size() - 1);
40 while(newFunctionId == oldFunctionId) {
41 newFunctionId = cartesian->get_random_int(0, vRef.size() - 1);
43 uint newNumOfArgs = vRef[newFunctionId]->getNumOfArgs();
45 cartesian->operator[](toBeMutated).value = newFunctionId;
48 if(oldNumOfArgs < newNumOfArgs){
49 uint rowNumber = cartesian->getRowNumber(toBeMutated);
50 while(oldNumOfArgs < newNumOfArgs) {
52 cartesian->operator[](toBeMutated).inputConnections.push_back(connection);
56 else if(oldNumOfArgs > newNumOfArgs) {
57 while(oldNumOfArgs > newNumOfArgs) {
58 uint connection = cartesian->get_random_int(0, oldNumOfArgs - 1);
59 cartesian->operator[](toBeMutated).inputConnections.erase(cartesian->operator[](toBeMutated).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)
uint nOutputs
number of final outputs
std::vector< std::vector< uint > > getActiveTrails()
bool mutate(GenotypeP gene)
Performs mutation of a genotype object. The genotype object must be initialized!
bool initialize(StateP state)
Initialize mutation operator. Called before first mutation operation.
void registerParameters(StateP state)
Register parameters with the system. Called before MutationOp::initialize.