5#include "SelectionOperator.h"
37 return state->getRegistry()->registerEntry(
name_ +
"." + name, value, T, description);
48 return state->getRegistry()->getEntry(
name_ +
"." + name);
52 std::vector<IndividualP> requests_,
stored_;
54 std::vector<IndividualP> demeCopy_;
58 uint totalEvaluations_, wastedEvaluations_;
62 SelectionOperatorP selBestOp;
65 IndividualP currentBest_;
67 std::vector<IndividualP> storedInds_;
130 virtual void read() {}
141 ECF_LOG(state, 4,
name_ +
": starting generation");
144 for(uint iDeme = 0; iDeme < state->getPopulation()->size(); iDeme++) {
145 activeDeme_ = state->getPopulation()->at(iDeme);
149 ECF_LOG(state, 4,
name_ +
": ending generation");
159 state_->getContext()->evaluatedIndividual = ind;
160 ECF_LOG(state_, 5,
"Evaluating individual: " + ind->toString());
161 ind->fitness =
evalOp_->evaluate(ind);
162 ECF_LOG(state_, 5,
"New fitness: " + ind->fitness->toString());
163 state_->increaseEvaluations();
169 uint
mutate(
const std::vector<IndividualP>& pool)
177 std::vector<IndividualP> pool;
178 pool.push_back(victim);
188 { activeDeme_->replace(oldInd->index, newInd); }
196 { activeDeme_->replace(oldIndId, newInd); }
236 state_->getContext()->evaluatedIndividual = ind;
237 ECF_LOG(state_, 5,
"Evaluating individual: " + ind->toString());
238 ind->fitness =
evalOp_->evaluate(ind);
239 ECF_LOG(state_, 5,
"New fitness: " + ind->fitness->toString());
240 state_->increaseEvaluations();
249 std::vector<IndividualP> pool;
250 pool.push_back(victim);
255 uint
mutate(
const std::vector<IndividualP>& pool)
259 for(uint i = 0; i < pool.size(); i++) {
276 {
replaceWith(state_->getPopulation()->getLocalDeme()->at(oldIndId), newInd); }
285 bool mate(IndividualP p1, IndividualP p2, IndividualP child)
291 IndividualP
copy(IndividualP source)
292 {
return (IndividualP) source->copy(); }
297 bool removeFrom(IndividualP victim, std::vector<IndividualP> &pool)
300 while(iWorst < pool.size() && pool[iWorst] != victim)
302 if(iWorst == pool.size())
304 pool.erase(pool.begin() + iWorst);
311 bool isMember(IndividualP single, std::vector<IndividualP> &pool)
314 while(index < pool.size() && pool[index] != single)
316 if(index == pool.size())
321typedef boost::shared_ptr<Algorithm> AlgorithmP;
std::vector< IndividualP > stored_
individual vectors for implicit evaluation
virtual bool advanceGeneration(StateP state)
Perform one generation of the algorithm on the whole population.
bool implicitParallelOperate(StateP state)
Parallel ECF: Worker processes in implicit parallel algorithm.
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.
virtual bool advanceGeneration(StateP state)
Parallel ECF: Perform one generation of the algorithm.
bool bSynchronized_
is implicit paralelization synchronous
void initializeImplicit(StateP state)
Parallel ECF: Initialize implicit parallel mode.
std::vector< uint > requestMutIds_
individual indexes for implicit mutation
bool bImplicitParallel_
implicit parallel flag
virtual bool advanceGeneration(StateP, DemeP)=0
Perform a single generation on a single deme.
std::vector< SelectionOperatorP > selectionOp
sel. operators used by algorithm
EvaluateOpP evalOp_
sptr to evaluation operator (set by the system)
void storeIndividual(IndividualP)
stores the individual (if it is consistent), resets consistency flag
std::string name_
algorithm name
virtual bool initialize(StateP)
Initialize the algorithm, read parameters from the system, do a sanity check.
std::vector< IndividualP > myJob_
worker's individual vector
uint mutate(const IndividualP victim)
Helper function: send a single individual to mutation.
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.
CrossoverP crossover_
sptr to container of crossover operators (set by the system)
voidP getParameterValue(StateP state, std::string name)
Helper function: get parameter value from the system.
virtual bool initializePopulation(StateP)
Evaluate initial population (called by State::run before evolution starts).
bool isMember(IndividualP single, std::vector< IndividualP > &pool)
Helper function: check if individual is in the pool.
bool mate(IndividualP p1, IndividualP p2, IndividualP child)
Helper function: crossover two individuals.
void setConsistency(IndividualP)
denotes current individual as consistent
void replaceWith(IndividualP oldInd, IndividualP newInd)
Helper function: replace an individual in current deme.
bool isImplicitParallel()
Is algorithm run in implicit parallel mode (in development, see tutorial).
bool removeFrom(IndividualP victim, std::vector< IndividualP > &pool)
Helper function: remove victim from pool of individual pointers.
MutationP mutation_
sptr to container of mutation operators (set by the system)
uint implicitMutate(IndividualP ind)
Parallel ECF: implicitly mutate an individual (store for later mutation in implicit parallel version)...
void registerParallelParameters(StateP state)
used only in parallel ECF
std::string getName()
Get algorithm name. Each algorithm is uniquely identified with its name.
std::vector< bool > isConsistent_
is individual (genotype-fitness pair) consistent
void restorePopulation()
restores inconsistent individuals to last consistent state
bool bImplicitMutation_
implicit mutation flag
bool initializeParallel(StateP state)
used only in parallel ECF
virtual void bcastTermination(StateP state)
Parallel ECF: broadcast termination to worker processes.
void evaluate(IndividualP ind)
Helper function: evaluate an individual.
void implicitEvaluate(IndividualP ind)
Parallel ECF: implicitly evaluate an individual (store for later evaluation in implicit parallel vers...
void replaceWith(uint oldIndId, IndividualP newInd)
Helper function: replace an individual at given position in current deme.
bool bImplicitEvaluation_
implicit evaluation flag
std::vector< std::vector< IndividualP > > sentInds_
individuals sent for evaluation
void restoreIndividuals(std::vector< uint >)
restores individuals whose fitness is received
void storeGenotypes(std::vector< IndividualP > &)
adds genotypes of individuals to 'sent' repository
std::vector< IndividualP > receivedMut_
individual vectors for implicit mutation
virtual void registerParameters(StateP)
Register algorithm's parameters (if any).
std::vector< uint > requestIds_
individual indexes for implicit evaluation
virtual bool isParallel()
Is algorithm parallel (false by default for all algorithms not inheriting ParallelAlgorithm class).
type
Data types used for configuration file parameters.