2#include "ECF_derived.h"
5#include "AlgAEliGPEA2.h"
11AlgAEliGpea2::AlgAEliGpea2()
13 name_ =
"AlgAEliGPEA2";
20 int* tsizep =
new int(3);
21 state->getRegistry()->registerEntry(
name_ +
".tsize", (voidP) tsizep, ECF::UINT);
23 uint* jobSize =
new uint(10);
24 state->getRegistry()->registerEntry(
name_ +
".jobsize", (voidP) jobSize, ECF::UINT);
29 if(state->getCommunicator()->getCommRank() != MASTER)
35 voidP tsizep = state->getRegistry()->getEntry(
name_ +
".tsize");
36 nTournament = *((uint*) tsizep.get());
38 voidP jobSizeP = state->getRegistry()->getEntry(
name_ +
".jobsize");
39 jobSize = *((uint*) jobSizeP.get());
46 CommunicatorP comm = state->getCommunicator();
48 if(comm->getCommRank() == MASTER) {
50 std::vector<IndividualP> evalPool;
53 while(iIter < deme->size()) {
56 for(uint ind = 0; ind < jobSize && iIter < deme->size(); ind++, iIter++) {
57 std::vector<IndividualP> tournament;
58 for (uint i = 0; i < nTournament; ++i) {
59 tournament.push_back(
selectionOp[RANDOM]->select(*deme));
62 IndividualP worst =
selectionOp[WORST]->select(tournament);
65 crossover_->mate(tournament[0], tournament[1], worst);
67 std::vector<IndividualP> mutationPool;
68 mutationPool.push_back(worst);
71 if(
isMember(worst, evalPool) ==
false)
72 evalPool.push_back(worst);
79 comm->recvDemeFitness(*deme, Comm::ANY_PROCESS);
80 uint iWorker = comm->getLastSource();
82 comm->sendIndividuals(evalPool, iWorker);
103 uint remainingWorkers = comm->getCommSize() - 1;
104 while(remainingWorkers > 0) {
105 comm->recvDemeFitness(*deme, Comm::ANY_PROCESS);
106 uint iWorker = comm->getLastSource();
108 comm->sendIndividuals(evalPool, iWorker);
114 std::vector<IndividualP> empty;
116 comm->sendFitness(empty, MASTER);
119 myJobSize = comm->recvReplaceIndividuals(myJob, MASTER);
122 while(myJobSize > 0) {
123 for(uint i = 0; i < myJobSize; i++)
126 comm->sendFitness(myJob, MASTER, myJobSize);
128 myJobSize = comm->recvReplaceIndividuals(myJob, MASTER);
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.
std::vector< SelectionOperatorP > selectionOp
sel. operators used by algorithm
std::string name_
algorithm name
CrossoverP crossover_
sptr to container of crossover operators (set by the system)
bool isMember(IndividualP single, std::vector< IndividualP > &pool)
Helper function: check if individual is in the pool.
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)
void evaluate(IndividualP ind)
Helper function: evaluate an individual.
Random individual selection operator.
Worst individual selection operator.