ECF 1.5
Deme.cpp
1#include "ECF_base.h"
2#include<sstream>
3
4
5bool Deme::initialize(StateP state)
6{
7 for(uint i = 0; i < nIndividuals_; i++) {
8 this->push_back(static_cast<IndividualP> (new Individual));
9 this->back()->index = (unsigned int) this->size() - 1;
10 this->back()->initialize(state);
11 }
12
13 hof_ = static_cast<HallOfFameP> (new HallOfFame);
14 hof_->initialize(state);
15
16 stats_ = static_cast<StatCalcP> (new StatCalc);
17 stats_->initialize(state);
18
19 return true;
20}
21
22
23bool Deme::replace(uint index, IndividualP newInd)
24{
25 newInd->index = index;
26 (*this)[index] = newInd;
27 return true;
28}
29
30
31void Deme::write(XMLNode &xDeme)
32{
33 xDeme = XMLNode::createXMLTopNode("Deme");
34 std::stringstream value;
35 value << nIndividuals_;
36 xDeme.addAttribute("size", value.str().c_str());
37
38 XMLNode xHoF;
39 hof_->write(xHoF);
40 xDeme.addChild(xHoF);
41
42 XMLNode xIndividual;
43 for(uint i = 0; i < this->size(); i++) {
44 this->at(i)->write(xIndividual);
45 xDeme.addChild(xIndividual);
46 }
47}
48
49
54void Deme::read(XMLNode &xDeme)
55{
56 XMLNode xHof = xDeme.getChildNode(0);
57 this->hof_->read(xHof);
58
59 for(uint i = 0; i < this->size(); i++) {
60 XMLNode xInd = xDeme.getChildNode((int)i + 1);
61 this->at(i)->read(xInd);
62 }
63}
void read(XMLNode &)
Definition: Deme.cpp:54
bool replace(uint index, IndividualP newInd)
replace ind. at index with newInd
Definition: Deme.cpp:23
bool initialize(StateP state)
initialize deme
Definition: Deme.cpp:5
Records a set of best-so-far individuals.
Definition: HallOfFame.h:14
Individual class - inherits a vector of Genotype objects.
Definition: Individual.h:12
Statistics calculation class.
Definition: StatCalc.h:20