2#include "AlgElimination.h"
6Elimination :: Elimination()
11 selRandomOp =
static_cast<SelRandomOpP
> (
new SelRandomOp);
12 selBestOp =
static_cast<SelBestOpP
> (
new SelBestOp);
19 "generation gap (percentage of population to be eliminated)");
21 "selection pressure: how much is the worst individual 'worse' than the best");
27 selFitPropOp->initialize(state);
28 selRandomOp->initialize(state);
29 selBestOp->initialize(state);
32 genGap_ = *((
double*) genGapP.get());
34 if(genGap_ <= 0 || genGap_ > 1) {
35 ECF_LOG_ERROR(state,
"Error: generation gap parameter in Elimination algorithm must be in <0, 1]!");
52 IndividualP best = selBestOp->select(*deme);
56 std::vector<IndividualP> newGen;
57 for(uint i = 0; i < deme->size(); i++)
58 newGen.push_back(deme->at(i));
61 uint generationGap = (uint) (
genGap_ * deme->size());
62 for(uint i = 0; i < generationGap; i++) {
63 IndividualP victim = selFitPropOp->select(newGen);
68 for(uint i = 0; i < generationGap; i++) {
69 IndividualP parent1 = selRandomOp->select(*deme);
70 IndividualP parent2 = selRandomOp->select(*deme);
71 IndividualP child =
copy(parent1);
72 mate(parent1, parent2, child);
73 newGen.push_back(child);
77 for(uint i = 0; i < deme->size(); i++)
84 for(uint i = 0; i < deme->size(); i++)
85 if(!deme->at(i)->fitness->isValid()) {
90 IndividualP random = selFitPropOp->select(*deme);
91 if(best->fitness->isBetterThan(random->fitness))
uint mutate(const std::vector< IndividualP > &pool)
Helper function: send a vector of individuals to mutation.
IndividualP copy(IndividualP source)
Helper function: make a copy of an individual.
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.
bool mate(IndividualP p1, IndividualP p2, IndividualP child)
Helper function: crossover two individuals.
void replaceWith(IndividualP oldInd, IndividualP newInd)
Helper function: replace an individual in current deme.
bool removeFrom(IndividualP victim, std::vector< IndividualP > &pool)
Helper function: remove victim from pool of individual pointers.
void evaluate(IndividualP ind)
Helper function: evaluate an individual.
double selPressure_
selection pressure
double genGap_
generation gap
bool advanceGeneration(StateP state, DemeP deme)
Perform a single generation on a single deme.
void registerParameters(StateP state)
Register algorithm's parameters (if any).
bool initialize(StateP state)
Initialize the algorithm, read parameters from the system, do a sanity check.
Best individual selection operator.
Fitness proportional (and inverse proportional) individual selection operator.
Random individual selection operator.