• Main Page
  • Modules
  • Classes
  • Files
  • File List

D:/Projekt/ECF_trunk/ECF/cartesian/CartesianMutOnePoint.cpp

00001 #include "CartesianMutOnePoint.h"
00002 #include <cmath>
00003 
00004 namespace cart{
00005 
00006 void CartesianMutOnePoint::registerParameters(StateP state)
00007 {
00008     //TODO: ako ce se jednog dana koristiti vise operatora
00009     //myGenotype_->registerParameter(state, "mut.onepoint", (voidP) new double(0), DOUBLE);
00010     myGenotype_->registerParameter(state, "mut.onepoint.prob", (voidP) new double(0.001), ECF::DOUBLE);
00011 }
00012 
00013 
00014 bool CartesianMutOnePoint::initialize(StateP state)
00015 {
00016     //TODO: ako ce se jednog dana koristiti vise operatora
00017     //voidP sptr = myGenotype_->getParameterValue(state, "mut.onepoint");
00018     //probability_ = *((double*)sptr.get());
00019 
00020     voidP sptr = myGenotype_->getParameterValue(state, "mut.onepoint.prob");
00021     mutProb_ = *((double*)sptr.get());
00022 
00023     useMutProb_ = false;
00024     if(myGenotype_->isParameterDefined(state, "mut.onepoint.prob"))
00025         useMutProb_ = true;
00026 
00027     return true;
00028 }
00029 
00030 
00031 bool CartesianMutOnePoint::mutate(GenotypeP gene)
00032 {
00033     Cartesian* mut = (Cartesian*) (gene.get());
00034 
00035     //if mutation probability is used, then choose values in genotpye to be mutated depending on the
00036     //predefined mutation probability
00037     if (useMutProb_)
00038     {
00039         for (int i = 0; i < mut->size(); i++)
00040         {
00041             if (state_->getRandomizer()->getRandomInteger(0, 1) < mutProb_)
00042             {
00043                 mutOneValue(mut, i);
00044             }
00045         }
00046     }
00047     //if mutation probability isn't used, then randomly choose one value in genotype to be mutated
00048     else
00049     {
00050         uint mutPoint = (uint)(state_->getRandomizer()->getRandomInteger(0, mut->size() - 1));
00051 
00052         mutOneValue(mut, mutPoint);
00053     }
00054 
00055     return true;
00056 }
00057 
00058 void CartesianMutOnePoint::mutOneValue(Cartesian *mut, int mutPoint)
00059 {
00060     //value chosen to be mutated in either input connection or function token
00061     if (mutPoint < (mut->getNumOfRows() * mut->getNumOfCols() * (mut->getNumOfInputConn() + 1)))
00062     {
00063         //chosen value represents function token
00064         if (((mutPoint + 1) % (mut->getNumOfInputConn() + 1) == 0))
00065         {
00066             mut->at(mutPoint) = mut->randFunction();
00067         }
00068         //chosen value represents input connection
00069         else
00070         {
00071             double num = (double)mutPoint / (double)(mut->getNumOfRows() * (mut->getNumOfInputConn() + 1));
00072             //column in which input connection of current node is placed
00073             uint currCol = (uint)floor(num) + 1;
00074             mut->at(mutPoint) = mut->randInputConn(currCol - 1);
00075         }
00076     }
00077     //chosen value represents output
00078     else
00079     {
00080         mut->at(mutPoint) = mut->randOutput();
00081     }
00082 }
00083 
00084 }
00085 

Generated on Tue Nov 4 2014 13:04:30 for ECF by  doxygen 1.7.1