5Individual::Individual(StateP state)
18 for(uint i = 0; i < state->getGenotypes().size(); i++) {
19 this->push_back(
static_cast<GenotypeP
> (state->getGenotypes()[i]->copy()));
20 (*this)[i]->setGenotypeId(i);
24 for(uint i = 0; i < this->size(); i++)
25 (*
this)[i]->initialize(state);
38 for(uint i = 0; i < this->size(); i++)
39 c->push_back((GenotypeP) (this->at(i)->copy()));
46 return this->at(
index);
64 xIndividual = XMLNode::createXMLTopNode(
"Individual");
65 std::stringstream sValue;
66 sValue << this->size();
67 xIndividual.addAttribute(
"size", sValue.str().c_str());
72 xIndividual.addChild(xFitness);
74 XMLNode xFitness = XMLNode::createXMLTopNode(
"Fitness");
75 xIndividual.addChild(xFitness);
79 for(uint i = 0; i < this->size(); i++) {
80 this->at(i)->write(xGenotype);
81 xIndividual.addChild(xGenotype);
90 char *s = xInd.createXMLString();
105 XMLNode xFit = xIndividual.getChildNode(0);
108 fitness =
static_cast<FitnessP
> (state_->getFitnessObject()->copy());
111 for(uint i = 0; i < this->size(); i++) {
112 XMLNode xGen = xIndividual.getChildNode((
int)i + 1);
113 this->at(i)->read(xGen);
Individual class - inherits a vector of Genotype objects.
FitnessP getFitness()
return sptr to individual's fitness object
uint cid
coherence index, used in asynchronous parallel algoritmhs
GenotypeP getGenotype(uint index=0)
return genotype with given index
void write(XMLNode &)
write individual to XML node
void read(XMLNode &)
read individual from XML node
bool initialize(StateP state)
initialize individual
std::string toString()
output individual to string
FitnessP fitness
sptr to individual's fitness object
uint index
individual's index in Deme
Individual * copy()
create a copy of the individual