3#include "SelRandomOp.h"
4#include "AlgDifferentialEvolution.h"
5#include "floatingpoint/FloatingPoint.h"
9DifferentialEvolution::DifferentialEvolution()
12 name_ =
"DifferentialEvolution";
18 selRandomOp =
static_cast<SelectionOperatorP
> (
new SelRandomOp);
24 registerParameter(state,
"F", (voidP)
new double(1.), ECF::DOUBLE,
"scaling constant");
25 registerParameter(state,
"CR", (voidP)
new double(0.9), ECF::DOUBLE,
"crossover rate");
27 "should the algorithm respect the bounds defined in the genotype or not (default: 0)");
33 selRandomOp->initialize(state);
40 CR_ = *((
double*) CR.get());
44 GenotypeP activeGenotype = state->getGenotypes()[0];
45 RealValueGenotypeP rv = boost::dynamic_pointer_cast<RealValueGenotype> (activeGenotype);
47 ECF_LOG_ERROR(state,
"Error: Differential evolution algorithm accepts only a RealValueGenotype derived genotype! (FloatingPoint or Binary)");
61 for(uint iIter = 0; iIter < deme->size(); iIter++){
66 for(uint iIter = 0; iIter < deme->size(); iIter++) {
71 for(uint iIter = 0; iIter < deme->size(); iIter++) {
73 if(
donor_vector[iIter]->fitness->isBetterThan(deme->at(iIter)->fitness))
90 IndividualP ind1, ind2, ind3;
93 ind1 = selRandomOp->select(*deme);
94 ind2 = selRandomOp->select(*deme);
95 while (ind1->index == ind2->index)
96 ind2 = selRandomOp->select(*deme);
97 ind3 = selRandomOp->select(*deme);
98 while (ind1->index == ind3->index || ind2->index == ind3->index)
99 ind3 = selRandomOp->select(*deme);
112 for(uint i = 0; i < flp2->
realValue.size(); i++){
117 if(donor_value < b->getLBound())
139 for(uint i = 0; i < flp1->
realValue.size(); i++) {
140 if (state->getRandomizer()->getRandomDouble() <=
CR_ || i == state->getRandomizer()->getRandomInteger(dim)) {
std::string name_
algorithm name
bool registerParameter(StateP state, std::string name, voidP value, enum ECF::type T, std::string description="")
Helper function: register a single parameter with the system.
voidP getParameterValue(StateP state, std::string name)
Helper function: get parameter value from the system.
void replaceWith(IndividualP oldInd, IndividualP newInd)
Helper function: replace an individual in current deme.
void evaluate(IndividualP ind)
Helper function: evaluate an individual.
bool initialize(StateP state)
Initialize the algorithm, read parameters from the system, do a sanity check.
void registerParameters(StateP state)
Register algorithm's parameters (if any).
std::vector< IndividualP > donor_vector
vector of donor solutions (individuals)
bool bounded_
constrained or not
void crossover(DemeP deme, uint index, StateP state)
cross donor vectors with population members to create trial vectors
double Fconst_
scaling constant
bool advanceGeneration(StateP state, DemeP deme)
Perform a single generation on a single deme.
void createDonorVectors(DemeP deme, StateP state)
create donor vectors (the same number as the population size)
Individual class - inherits a vector of Genotype objects.
RealValueGenotype class - abstract genotype class for genotypes that represent a vector of real value...
double getUBound()
return upper bound of the defined interval
std::vector< double > realValue
vector of floating point values
double getLBound()
return lower bound of the defined interval
Random individual selection operator.