ECF 1.5
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Algorithm Class Referenceabstract

Algorithm base class. More...

#include <Algorithm.h>

Inheritance diagram for Algorithm:
AlgAEliGpea2 AlgNSGA2 ArtificialBeeColony Clonalg CuckooSearch DifferentialEvolution Elimination EvolutionStrategy GenHookeJeeves GeneticAnnealing MyAlg OptIA ParallelAlgorithm ParticleSwarmOptimization RandomSearch RouletteWheel Solver SteadyStateTournament XCS

Public Member Functions

std::string getName ()
 Get algorithm name. Each algorithm is uniquely identified with its name. More...
 
virtual bool isParallel ()
 Is algorithm parallel (false by default for all algorithms not inheriting ParallelAlgorithm class). More...
 
bool isImplicitParallel ()
 Is algorithm run in implicit parallel mode (in development, see tutorial). More...
 
virtual bool advanceGeneration (StateP, DemeP)=0
 Perform a single generation on a single deme. More...
 
virtual bool initialize (StateP)
 Initialize the algorithm, read parameters from the system, do a sanity check. More...
 
virtual void registerParameters (StateP)
 Register algorithm's parameters (if any). More...
 
virtual bool initializePopulation (StateP)
 Evaluate initial population (called by State::run before evolution starts). More...
 
virtual void read ()
 
virtual bool advanceGeneration (StateP state)
 Perform one generation of the algorithm on the whole population. More...
 
void evaluate (IndividualP ind)
 Helper function: evaluate an individual. More...
 
uint mutate (const std::vector< IndividualP > &pool)
 Helper function: send a vector of individuals to mutation. More...
 
uint mutate (const IndividualP victim)
 Helper function: send a single individual to mutation. More...
 
void replaceWith (IndividualP oldInd, IndividualP newInd)
 Helper function: replace an individual in current deme. More...
 
void replaceWith (uint oldIndId, IndividualP newInd)
 Helper function: replace an individual at given position in current deme. More...
 
void registerParallelParameters (StateP state)
 used only in parallel ECF More...
 
bool initializeParallel (StateP state)
 used only in parallel ECF More...
 
virtual bool advanceGeneration (StateP state)
 Parallel ECF: Perform one generation of the algorithm.
 
virtual void bcastTermination (StateP state)
 Parallel ECF: broadcast termination to worker processes. More...
 
void registerParallelParameters (StateP state)
 Parallel ECF: Register parameters for implicit parallel algorithm version.
 
bool initializeParallel (StateP state)
 Parallel ECF: Initialize implicit parallel algorithm.
 
void initializeImplicit (StateP state)
 Parallel ECF: Initialize implicit parallel mode. More...
 
bool implicitParallelOperate (StateP state)
 Parallel ECF: Worker processes in implicit parallel algorithm. More...
 
void evaluate (IndividualP ind)
 Parallel ECF: evaluate an individual. More...
 
void implicitEvaluate (IndividualP ind)
 Parallel ECF: implicitly evaluate an individual (store for later evaluation in implicit parallel version). More...
 
uint mutate (const IndividualP victim)
 Parallel ECF: immediately mutate an individual. More...
 
uint mutate (const std::vector< IndividualP > &pool)
 Parallel ECF: mutate a vector of individuals. More...
 
uint implicitMutate (IndividualP ind)
 Parallel ECF: implicitly mutate an individual (store for later mutation in implicit parallel version). More...
 
void replaceWith (IndividualP oldInd, IndividualP newInd)
 Parallel ECF: replace an individual in a deme.
 
void replaceWith (uint oldIndId, IndividualP newInd)
 Parallel ECF: replace an individual at given position in a deme. More...
 
bool mate (IndividualP p1, IndividualP p2, IndividualP child)
 Helper function: crossover two individuals. More...
 
IndividualP copy (IndividualP source)
 Helper function: make a copy of an individual. More...
 
bool removeFrom (IndividualP victim, std::vector< IndividualP > &pool)
 Helper function: remove victim from pool of individual pointers. More...
 
bool isMember (IndividualP single, std::vector< IndividualP > &pool)
 Helper function: check if individual is in the pool. More...
 

Public Attributes

CrossoverP crossover_
 sptr to container of crossover operators (set by the system) More...
 
MutationP mutation_
 sptr to container of mutation operators (set by the system) More...
 
EvaluateOpP evalOp_
 sptr to evaluation operator (set by the system) More...
 
StateP state_
 

Protected Member Functions

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. More...
 
voidP getParameterValue (StateP state, std::string name)
 Helper function: get parameter value from the system. More...
 
void storeIndividual (IndividualP)
 stores the individual (if it is consistent), resets consistency flag More...
 
void storeGenotypes (std::vector< IndividualP > &)
 adds genotypes of individuals to 'sent' repository More...
 
void setConsistency (IndividualP)
 denotes current individual as consistent More...
 
void restoreIndividuals (std::vector< uint >)
 restores individuals whose fitness is received More...
 
void restorePopulation ()
 restores inconsistent individuals to last consistent state More...
 

Protected Attributes

DemeP activeDeme_
 
std::string name_
 algorithm name More...
 
bool bImplicitParallel_
 implicit parallel flag More...
 
std::vector< SelectionOperatorP > selectionOp
 sel. operators used by algorithm More...
 
std::vector< IndividualP > requests_
 
std::vector< IndividualP > stored_
 individual vectors for implicit evaluation More...
 
std::vector< uint > requestIds_
 individual indexes for implicit evaluation More...
 
std::vector< IndividualP > demeCopy_
 
std::vector< IndividualP > myJob_
 worker's individual vector More...
 
CommunicatorP comm_
 
uint jobSize_
 
uint totalEvaluations_
 
uint wastedEvaluations_
 
bool bImplicitEvaluation_
 implicit evaluation flag More...
 
bool bImplicitMutation_
 implicit mutation flag More...
 
bool bSynchronized_
 is implicit paralelization synchronous More...
 
SelectionOperatorP selBestOp
 
std::vector< IndividualP > requestsMut_
 
std::vector< IndividualP > receivedMut_
 individual vectors for implicit mutation More...
 
std::vector< uint > requestMutIds_
 individual indexes for implicit mutation More...
 
IndividualP currentBest_
 
std::vector< IndividualP > storedInds_
 
std::vector< std::vector< IndividualP > > sentInds_
 individuals sent for evaluation More...
 
std::vector< bool > isConsistent_
 is individual (genotype-fitness pair) consistent More...
 

Detailed Description

Algorithm base class.

All algorithms must inherit this one. An algorithm combines selection operators (SelectionOperator), crossover (Algorithm::mate), mutation (Algorithm::mutate) and additional logic to build an evolutionary procedure.

Definition at line 19 of file Algorithm.h.

Constructor & Destructor Documentation

◆ Algorithm()

Algorithm::Algorithm ( )
inline

Definition at line 85 of file Algorithm.h.

◆ ~Algorithm()

virtual Algorithm::~Algorithm ( )
inlinevirtual

Definition at line 88 of file Algorithm.h.

Member Function Documentation

◆ advanceGeneration() [1/2]

bool Algorithm::advanceGeneration ( StateP  state)
inlinevirtual

Perform one generation of the algorithm on the whole population.

Default if not reimplemented: algorithm advances one generation on each deme

Definition at line 139 of file Algorithm.h.

◆ advanceGeneration() [2/2]

virtual bool Algorithm::advanceGeneration ( StateP  ,
DemeP   
)
pure virtual

◆ bcastTermination()

void Algorithm::bcastTermination ( StateP  state)
virtual

Parallel ECF: broadcast termination to worker processes.

Reimplemented in AlgAEliGpea.

Definition at line 290 of file Algorithm.cpp.

◆ copy()

IndividualP Algorithm::copy ( IndividualP  source)
inline

Helper function: make a copy of an individual.

Definition at line 291 of file Algorithm.h.

◆ evaluate() [1/2]

void Algorithm::evaluate ( IndividualP  ind)
inline

Helper function: evaluate an individual.

Definition at line 157 of file Algorithm.h.

◆ evaluate() [2/2]

void Algorithm::evaluate ( IndividualP  ind)
inline

Parallel ECF: evaluate an individual.

Definition at line 227 of file Algorithm.h.

◆ getName()

std::string Algorithm::getName ( )
inline

Get algorithm name. Each algorithm is uniquely identified with its name.

Definition at line 92 of file Algorithm.h.

◆ getParameterValue()

voidP Algorithm::getParameterValue ( StateP  state,
std::string  name 
)
inlineprotected

Helper function: get parameter value from the system.

Parameters
statepointer to State object
nameparameter name
Returns
pointer to parameter value (needs casting)

Definition at line 46 of file Algorithm.h.

◆ implicitEvaluate()

void Algorithm::implicitEvaluate ( IndividualP  ind)

Parallel ECF: implicitly evaluate an individual (store for later evaluation in implicit parallel version).

Definition at line 117 of file Algorithm.cpp.

◆ implicitMutate()

uint Algorithm::implicitMutate ( IndividualP  ind)

Parallel ECF: implicitly mutate an individual (store for later mutation in implicit parallel version).

Definition at line 176 of file Algorithm.cpp.

◆ implicitParallelOperate()

bool Algorithm::implicitParallelOperate ( StateP  state)

Parallel ECF: Worker processes in implicit parallel algorithm.

Definition at line 239 of file Algorithm.cpp.

◆ initialize()

virtual bool Algorithm::initialize ( StateP  )
inlinevirtual

Initialize the algorithm, read parameters from the system, do a sanity check.

Called by the system before the algorithm starts (Algorithm::advanceGeneration)

Reimplemented in AlgAEliGpea, AlgAEliGpea2, ArtificialBeeColony, Clonalg, CuckooSearch, DifferentialEvolution, Elimination, EvolutionStrategy, GeneticAnnealing, GenHookeJeeves, AlgNSGA2, OptIA, ParticleSwarmOptimization, RandomSearch, RouletteWheel, AlgSGenGpea, SteadyStateTournament, MyAlg, XCS, SolverEvolutionStrategy, and SolverTournamentEA.

Definition at line 115 of file Algorithm.h.

◆ initializeImplicit()

void Algorithm::initializeImplicit ( StateP  state)

Parallel ECF: Initialize implicit parallel mode.

Definition at line 92 of file Algorithm.cpp.

◆ initializeParallel()

bool Algorithm::initializeParallel ( StateP  state)
inline

used only in parallel ECF

Definition at line 203 of file Algorithm.h.

◆ initializePopulation()

bool Algorithm::initializePopulation ( StateP  state)
virtual

Evaluate initial population (called by State::run before evolution starts).

Definition at line 338 of file Algorithm.cpp.

◆ isImplicitParallel()

bool Algorithm::isImplicitParallel ( )
inline

Is algorithm run in implicit parallel mode (in development, see tutorial).

Definition at line 100 of file Algorithm.h.

◆ isMember()

bool Algorithm::isMember ( IndividualP  single,
std::vector< IndividualP > &  pool 
)
inline

Helper function: check if individual is in the pool.

Definition at line 311 of file Algorithm.h.

◆ isParallel()

virtual bool Algorithm::isParallel ( )
inlinevirtual

Is algorithm parallel (false by default for all algorithms not inheriting ParallelAlgorithm class).

Reimplemented in ParallelAlgorithm.

Definition at line 96 of file Algorithm.h.

◆ mate()

bool Algorithm::mate ( IndividualP  p1,
IndividualP  p2,
IndividualP  child 
)
inline

Helper function: crossover two individuals.

Definition at line 285 of file Algorithm.h.

◆ mutate() [1/4]

uint Algorithm::mutate ( const IndividualP  victim)
inline

Helper function: send a single individual to mutation.

Definition at line 175 of file Algorithm.h.

◆ mutate() [2/4]

uint Algorithm::mutate ( const IndividualP  victim)
inline

Parallel ECF: immediately mutate an individual.

Definition at line 247 of file Algorithm.h.

◆ mutate() [3/4]

uint Algorithm::mutate ( const std::vector< IndividualP > &  pool)
inline

Helper function: send a vector of individuals to mutation.

Definition at line 169 of file Algorithm.h.

◆ mutate() [4/4]

uint Algorithm::mutate ( const std::vector< IndividualP > &  pool)
inline

Parallel ECF: mutate a vector of individuals.

Definition at line 255 of file Algorithm.h.

◆ read()

virtual void Algorithm::read ( )
inlinevirtual

Definition at line 130 of file Algorithm.h.

◆ registerParallelParameters()

void Algorithm::registerParallelParameters ( StateP  state)
inline

used only in parallel ECF

Definition at line 199 of file Algorithm.h.

◆ registerParameter()

bool Algorithm::registerParameter ( StateP  state,
std::string  name,
voidP  value,
enum ECF::type  T,
std::string  description = "" 
)
inlineprotected

Helper function: register a single parameter with the system.

Parameters
statepointer to State object
nameunique parameter name
valuepointer to parameter value object (caller provides)
Tparameter type (see Registry.h)
Returns
true if parameter successfuly registered, false otherwise

Definition at line 35 of file Algorithm.h.

◆ registerParameters()

virtual void Algorithm::registerParameters ( StateP  )
inlinevirtual

◆ removeFrom()

bool Algorithm::removeFrom ( IndividualP  victim,
std::vector< IndividualP > &  pool 
)
inline

Helper function: remove victim from pool of individual pointers.

Definition at line 297 of file Algorithm.h.

◆ replaceWith() [1/3]

void Algorithm::replaceWith ( IndividualP  oldInd,
IndividualP  newInd 
)
inline

Helper function: replace an individual in current deme.

Parameters
oldIndindividual to be replaced
newIndnew individual

Definition at line 187 of file Algorithm.h.

◆ replaceWith() [2/3]

void Algorithm::replaceWith ( uint  oldIndId,
IndividualP  newInd 
)
inline

Helper function: replace an individual at given position in current deme.

Parameters
oldIndIdindex of individual to be replaced
newIndnew individual

Definition at line 195 of file Algorithm.h.

◆ replaceWith() [3/3]

void Algorithm::replaceWith ( uint  oldIndId,
IndividualP  newInd 
)
inline

Parallel ECF: replace an individual at given position in a deme.

Definition at line 275 of file Algorithm.h.

◆ restoreIndividuals()

void Algorithm::restoreIndividuals ( std::vector< uint >  received)
protected

restores individuals whose fitness is received

Definition at line 455 of file Algorithm.cpp.

◆ restorePopulation()

void Algorithm::restorePopulation ( )
protected

restores inconsistent individuals to last consistent state

Definition at line 481 of file Algorithm.cpp.

◆ setConsistency()

void Algorithm::setConsistency ( IndividualP  ind)
protected

denotes current individual as consistent

Definition at line 424 of file Algorithm.cpp.

◆ storeGenotypes()

void Algorithm::storeGenotypes ( std::vector< IndividualP > &  pool)
protected

adds genotypes of individuals to 'sent' repository

Definition at line 432 of file Algorithm.cpp.

◆ storeIndividual()

void Algorithm::storeIndividual ( IndividualP  ind)
protected

stores the individual (if it is consistent), resets consistency flag

Definition at line 414 of file Algorithm.cpp.

Member Data Documentation

◆ activeDeme_

DemeP Algorithm::activeDeme_
protected

Definition at line 22 of file Algorithm.h.

◆ bImplicitEvaluation_

bool Algorithm::bImplicitEvaluation_
protected

implicit evaluation flag

Definition at line 59 of file Algorithm.h.

◆ bImplicitMutation_

bool Algorithm::bImplicitMutation_
protected

implicit mutation flag

Definition at line 60 of file Algorithm.h.

◆ bImplicitParallel_

bool Algorithm::bImplicitParallel_
protected

implicit parallel flag

Definition at line 24 of file Algorithm.h.

◆ bSynchronized_

bool Algorithm::bSynchronized_
protected

is implicit paralelization synchronous

Definition at line 61 of file Algorithm.h.

◆ comm_

CommunicatorP Algorithm::comm_
protected

Definition at line 56 of file Algorithm.h.

◆ crossover_

CrossoverP Algorithm::crossover_

sptr to container of crossover operators (set by the system)

Definition at line 80 of file Algorithm.h.

◆ currentBest_

IndividualP Algorithm::currentBest_
protected

Definition at line 65 of file Algorithm.h.

◆ demeCopy_

std::vector<IndividualP> Algorithm::demeCopy_
protected

Definition at line 54 of file Algorithm.h.

◆ evalOp_

EvaluateOpP Algorithm::evalOp_

sptr to evaluation operator (set by the system)

Definition at line 82 of file Algorithm.h.

◆ isConsistent_

std::vector<bool> Algorithm::isConsistent_
protected

is individual (genotype-fitness pair) consistent

Definition at line 69 of file Algorithm.h.

◆ jobSize_

uint Algorithm::jobSize_
protected

Definition at line 57 of file Algorithm.h.

◆ mutation_

MutationP Algorithm::mutation_

sptr to container of mutation operators (set by the system)

Definition at line 81 of file Algorithm.h.

◆ myJob_

std::vector<IndividualP> Algorithm::myJob_
protected

worker's individual vector

Definition at line 55 of file Algorithm.h.

◆ name_

std::string Algorithm::name_
protected

algorithm name

Definition at line 23 of file Algorithm.h.

◆ receivedMut_

std::vector<IndividualP> Algorithm::receivedMut_
protected

individual vectors for implicit mutation

Definition at line 63 of file Algorithm.h.

◆ requestIds_

std::vector<uint> Algorithm::requestIds_
protected

individual indexes for implicit evaluation

Definition at line 53 of file Algorithm.h.

◆ requestMutIds_

std::vector<uint> Algorithm::requestMutIds_
protected

individual indexes for implicit mutation

Definition at line 64 of file Algorithm.h.

◆ requests_

std::vector<IndividualP> Algorithm::requests_
protected

Definition at line 52 of file Algorithm.h.

◆ requestsMut_

std::vector<IndividualP> Algorithm::requestsMut_
protected

Definition at line 63 of file Algorithm.h.

◆ selBestOp

SelectionOperatorP Algorithm::selBestOp
protected

Definition at line 62 of file Algorithm.h.

◆ selectionOp

std::vector<SelectionOperatorP> Algorithm::selectionOp
protected

sel. operators used by algorithm

Definition at line 25 of file Algorithm.h.

◆ sentInds_

std::vector< std::vector<IndividualP> > Algorithm::sentInds_
protected

individuals sent for evaluation

Definition at line 68 of file Algorithm.h.

◆ state_

StateP Algorithm::state_

Definition at line 83 of file Algorithm.h.

◆ stored_

std::vector<IndividualP> Algorithm::stored_
protected

individual vectors for implicit evaluation

Definition at line 52 of file Algorithm.h.

◆ storedInds_

std::vector<IndividualP> Algorithm::storedInds_
protected

Definition at line 67 of file Algorithm.h.

◆ totalEvaluations_

uint Algorithm::totalEvaluations_
protected

Definition at line 58 of file Algorithm.h.

◆ wastedEvaluations_

uint Algorithm::wastedEvaluations_
protected

Definition at line 58 of file Algorithm.h.


The documentation for this class was generated from the following files: