5Population::Population()
18 uint *sizep =
new uint(100);
19 state->getRegistry()->registerEntry(
"population.size", (voidP) sizep, ECF::UINT,
20 "number of individuals (default: 100)");
21 uint *demep =
new uint(1);
22 state->getRegistry()->registerEntry(
"population.demes", (voidP) demep, ECF::UINT,
23 "number of demes (default: 1)");
25 stats_->registerParameters(state);
41 hof_->initialize(state);
46 voidP sptr = state->getRegistry()->getEntry(
"population.size");
48 sptr = state->getRegistry()->getEntry(
"population.demes");
49 nDemes_ = *((uint*) sptr.get());
51 for(uint i = 0; i <
nDemes_; i++){
52 this->push_back(
static_cast<DemeP
> (
new Deme));
54 this->back()->initialize(state);
67 XMLNode xHof = xPopulation.getChildNode(0);
68 this->
hof_->read(xHof);
70 for(uint i = 0; i < this->size(); i++) {
71 XMLNode xDeme = xPopulation.getChildNode((
int)i + 1);
72 this->at(i)->read(xDeme);
82 xPopulation = XMLNode::createXMLTopNode(NODE_POPULATION);
83 xPopulation.addAttribute(
"size", uint2str(
nDemes_).c_str());
87 xPopulation.addChild(xHoF);
89 for(uint iDeme = 0; iDeme <
nDemes_; iDeme++) {
91 this->at(iDeme)->write(xDeme);
92 xPopulation.addChild(xDeme);
102 ECF_LOG(state_, 4,
"Population: updating HoF and statistics of all demes");
105 for(uint iDeme = 0; iDeme < this->size(); iDeme++) {
106 DemeP deme = this->at(iDeme);
107 deme->stats_->operate(*(deme));
108 ECF_LOG(state_, 3,
"Deme: " + uint2str(iDeme));
116 for(uint iDeme = 1; iDeme < this->size(); iDeme++)
117 stats_->update(this->at(iDeme)->stats_->getStats());
118 ECF_LOG(state_, 3,
"Population:");
123 std::vector<IndividualP> pool;
124 for(uint iDeme = 0; iDeme < this->size(); iDeme++) {
125 this->at(iDeme)->hof_->operate(*(this->at(iDeme)));
126 std::vector<IndividualP> bestOfDeme = this->at(iDeme)->hof_->getBest();
127 for(uint i = 0; i < bestOfDeme.size(); i++)
128 pool.push_back(bestOfDeme[i]);
145 voidP sptr = state->getRegistry()->getEntry(
"population.size");
147 sptr = state->getRegistry()->getEntry(
"population.demes");
148 nDemes_ = *((uint*) sptr.get());
151 hof_->initialize(state);
154 stats_->initialize(state);
158 this->push_back(
static_cast<DemeP
> (
new Deme));
160 this->back()->initialize(state);
167 this->push_back(
static_cast<DemeP
> (
new Deme));
169 this->back()->initialize(state);
180 ECF_LOG(state_, 4,
"Population: updating HoF and statistics of all demes");
186 std::vector<IndividualP> bestPool = this->at(0)->hof_->getBest();
187 hof_->operate(bestPool);
196 if(state_->getCommunicator()->getCommGlobalRank() == 0) {
198 std::vector<IndividualP> bestPool, received;
199 bestPool = this->at(0)->hof_->getBest();
201 for(uint iDeme = 1; iDeme <
nDemes_; iDeme++) {
202 received = state_->getCommunicator()->recvIndividualsGlobal();
203 for(uint ind = 0; ind < received.size(); ind++)
204 bestPool.push_back(received[ind]);
207 hof_->operate(bestPool);
210 std::vector<double> statValues;
211 for(uint iDeme = 1; iDeme <
nDemes_; iDeme++) {
212 statValues = state_->getCommunicator()->recvValuesGlobal();
213 stats_->update(statValues);
215 ECF_LOG(state_, 3,
"Population: ");
220 std::vector<IndividualP> myBest = this->at(0)->hof_->getBest();
221 state_->getCommunicator()->sendIndividualsGlobal(myBest, 0);
223 std::vector<double> myStats =
stats_->getStats();
224 state_->getCommunicator()->sendValuesGlobal(myStats, 0);
235 CommunicatorP comm = state_->getCommunicator();
238 if(comm->getCommRank() != 0)
241 xPopulation = XMLNode::createXMLTopNode(NODE_POPULATION);
242 xPopulation.addAttribute(
"size", uint2str(
nDemes_).c_str());
246 xPopulation.addChild(xHoF);
250 this->at(0)->write(xDeme);
251 xPopulation.addChild(xDeme);
254 if(comm->getCommGlobalRank() == 0) {
255 for(uint iDeme = 1; iDeme <
nDemes_; iDeme++) {
257 voidP msg = comm->recvDataGlobal();
258 xDeme = XMLNode::parseString((
char*) msg.get(),
"Deme");
259 xPopulation.addChild(xDeme);
263 char* message = xDeme.createXMLString();
264 comm->sendDataGlobal((voidP) message, (uint) strlen(message), 0);
275 CommunicatorP comm = state_->getCommunicator();
278 if(comm->getCommRank() != 0)
281 XMLNode xHof = xPopulation.getChildNode(0);
282 this->
hof_->read(xHof);
Deme class - inherits a vector of Individual objects.
Records a set of best-so-far individuals.
DemeP getLocalDeme()
get first deme (local deme in parallel ECF)
void read(XMLNode &)
Read population from XMLNode (serial ECF). Population must be initialize()-d beforehand!
uint myDemeIndex_
global index of local deme (at local process) - PECF only
uint nDemes_
total number of demes in the population
uint getLocalDemeId()
return local deme index (local process in parallel ECF)
StatCalcP stats_
population statistics
bool initialize(StateP state)
Initialize population (serial ECF).
uint nIndividuals_
number of individuals (in each deme!)
void write(XMLNode &)
Write population to XMLNode (serial ECF).
void registerParameters(StateP state)
register population specific parameters
void updateDemeStats()
Update, gather and write statistics of all demes; update and gather HallOfFame of all demes.
HallOfFameP hof_
population HallOfFame
Statistics calculation class.