2#include "ECF_derived.h"
5#include "AlgAEliGPEA.h"
12AlgAEliGpea::AlgAEliGpea()
14 name_ =
"AlgAEliGPEA";
22 int* tsizep =
new int(3);
23 state->getRegistry()->registerEntry(
name_ +
".tsize", (voidP) tsizep, ECF::UINT);
25 uint* jobSize =
new uint(10);
26 state->getRegistry()->registerEntry(
name_ +
".jobsize", (voidP) jobSize, ECF::UINT);
32 if(state->getCommunicator()->getCommRank() != MASTER)
38 voidP tsizep = state->getRegistry()->getEntry(
name_ +
".tsize");
39 nTournament_ = *((uint*) tsizep.get());
41 if(nTournament_ < 3) {
42 ECF_LOG_ERROR(state,
"Error: AlgAEliGPEA algorithm requires minimum tournament size of 3!");
46 voidP jobSizeP = state->getRegistry()->getEntry(
name_ +
".jobsize");
47 jobSize_ = *((uint*) jobSizeP.get());
53IndividualP AlgAEliGpea::performSingleTournament(DemeP deme)
55 std::vector<IndividualP> tournament;
56 for (uint i = 0; i < nTournament_; ++i) {
57 tournament.push_back(
selectionOp[RANDOM]->select(*deme));
60 IndividualP worst =
selectionOp[WORST]->select(tournament);
65 mate(tournament[0], tournament[1], worst);
75 CommunicatorP comm = state->getCommunicator();
77 if(comm->getCommRank() == MASTER) {
79 std::vector<IndividualP> evalPool;
82 while(iIter < deme->size()) {
85 for(uint ind = 0; ind < jobSize_ && iIter < deme->size(); ind++, iIter++) {
86 IndividualP newInd = performSingleTournament(deme);
88 if(
isMember(newInd, evalPool) ==
false)
89 evalPool.push_back(newInd);
95 if(!evalPool.empty() && comm->messageWaiting()) {
96 std::vector<uint> received = comm->recvFitnessVector(*deme, Comm::ANY_PROCESS);
97 state->increaseEvaluations((uint) received.size());
98 uint iWorker = comm->getLastSource();
102 comm->sendIndividuals(evalPool, iWorker);
114 IndividualP newInd = performSingleTournament(deme);
116 if(
isMember(newInd, evalPool) ==
false)
117 evalPool.push_back(newInd);
119 }
while(iIter < deme->size());
127 comm->sendFitness(myJob_, MASTER);
131 while(myJobSize != 0) {
133 myJobSize = comm->recvReplaceIndividuals(myJob_, MASTER);
134 for(uint i = 0; i < myJobSize; i++)
137 comm->sendFitness(myJob_, MASTER, myJobSize);
139 ECF_LOG(state, 4,
"Worker ends...");
149 if(state->getCommunicator()->getCommRank() == 0 && state->getTerminateCond()) {
150 std::vector<IndividualP> empty;
151 DemeP myDeme = state->getPopulation()->getLocalDeme();
153 for(uint iWorker = 1; iWorker < state->getCommunicator()->getCommSize(); iWorker++) {
154 if(state->getCommunicator()->messageWaiting(iWorker)) {
155 std::vector<uint> received = state->getCommunicator()->recvFitnessVector(*myDeme, Comm::ANY_PROCESS);
158 state->getCommunicator()->sendIndividuals(empty, iWorker);
166 else if(state->getCommunicator()->getCommRank() != 0)
167 state->setTerminateCond();
void registerParameters(StateP state)
Register algorithm's parameters (if any).
bool advanceGeneration(StateP state, DemeP deme)
Perform a single generation on a single deme.
void bcastTermination(StateP)
Parallel ECF: broadcast termination to worker processes.
bool initialize(StateP state)
Initialize the algorithm, read parameters from the system, do a sanity check.
uint mutate(const std::vector< IndividualP > &pool)
Helper function: send a vector of individuals to mutation.
std::vector< SelectionOperatorP > selectionOp
sel. operators used by algorithm
void storeIndividual(IndividualP)
stores the individual (if it is consistent), resets consistency flag
std::string name_
algorithm name
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
bool removeFrom(IndividualP victim, std::vector< IndividualP > &pool)
Helper function: remove victim from pool of individual pointers.
void restorePopulation()
restores inconsistent individuals to last consistent state
void evaluate(IndividualP ind)
Helper function: evaluate an individual.
void restoreIndividuals(std::vector< uint >)
restores individuals whose fitness is received
void storeGenotypes(std::vector< IndividualP > &)
adds genotypes of individuals to 'sent' repository
Random individual selection operator.
Worst individual selection operator.