1#include "../ECF_base.h" 
    7void BinaryMutSimple::registerParameters(StateP state)
 
    9    myGenotype_->registerParameter(state, 
"mut.simple", (voidP) 
new double(0), DOUBLE);
 
   10    myGenotype_->registerParameter(state, 
"mut.simple.bitprob", (voidP) 
new double(0.001), DOUBLE);
 
   11    myGenotype_->registerParameter(state, 
"mut.simple.extra", (voidP) 
new uint(1), UINT);
 
   15bool BinaryMutSimple::initialize(StateP state)
 
   17    voidP sptr = myGenotype_->getParameterValue(state, 
"mut.simple");
 
   18    probability_ = *((
double*)sptr.get());
 
   20    sptr = myGenotype_->getParameterValue(state, 
"mut.simple.bitprob");
 
   21    bitProb_ = *((
double*)sptr.get());
 
   24    if(myGenotype_->isParameterDefined(state, 
"mut.simple.bitprob"))
 
   27    sptr = myGenotype_->getParameterValue(state, 
"mut.simple.extra");
 
   28    extraTime = *((uint*)sptr.get());
 
   34bool BinaryMutSimple::mutate(GenotypeP gene)
 
   36    Binary* bin = (Binary*) (gene.get());
 
   42    for(uint i = 0; i < extraTime * bin->variables.size() * bin->getNumBits(); i++) 
 
   43        if(state_->getRandomizer()->getRandomDouble() < bitProb_)
 
   49        for(uint i = 0; i < bin->variables.size(); i++)
 
   50            for(uint j = 0; j < bin->getNumBits(); j++)
 
   51                if(state_->getRandomizer()->getRandomDouble() < bitProb_)
 
   52                    bin->variables[i][j] = !(bin->variables[i][j]);
 
   56        uint iBit = state_->getRandomizer()->getRandomInteger((uint) bin->getNumBits());
 
   57        uint dimension = state_->getRandomizer()->getRandomInteger((uint) bin->variables.size());
 
   58        bin->variables[dimension][iBit] = !(bin->variables[dimension][iBit]);
 
   66    IndividualP myInd = state_->getAlgorithm()->mutation_->currentInd;
 
   67    FitnessP current, modified;
 
   68    double precision = 1 / pow(10., (
int) bin->nDecimal_);
 
   70    current = state_->getAlgorithm()->evalOp_->evaluate(myInd);
 
   72    for(uint i = 0; i < bin->variables.size(); i++) {
 
   73        double newVal = bin->realValue[i];
 
   75        bin->realValue[i] += precision;
 
   76        modified = state_->getAlgorithm()->evalOp_->evaluate(myInd);
 
   77        if(modified->isBetterThan(current)) {
 
   79            newVal = bin->realValue[i];
 
   82        bin->realValue[i] -= 2 * precision;
 
   83        modified = state_->getAlgorithm()->evalOp_->evaluate(myInd);
 
   84        if(modified->isBetterThan(current)) {
 
   86            newVal = bin->realValue[i];
 
   89        bin->realValue[i] = newVal;
 
   93    for(uint iVar = 0; iVar < bin->nDimension_; iVar++) {
 
   94        bin->decValue[iVar] = 
static_cast<long int> ((bin->realValue[iVar] - bin->minValue_) / (bin->maxValue_ - bin->minValue_) * bin->potention_);
 
   96        long dec = bin->decValue[iVar];
 
   97        for (
int iBit = bin->nBits_; iBit > 0; dec = dec/2, iBit--) {
 
   98            bin->vBool_[iBit - 1] = (dec % 2) ? 
true:
false;
 
  100        bin->variables[iVar] = bin->vBool_;
 
  102        if(bin->bRounding_) {
 
  103            bin->realValue[iVar] = bin->round(bin->realValue[iVar], bin->nDecimal_);