Hello,
I need to do something like this (that doens't compile); but anyway It's a bit wrong:
class Gene {
char _allele;
char getAllele() { return _allele; }
...................................
class Chromosome {
static const int _length = 5;
vector<Gene> _reppresentation;
vector<Gene>& getReppresentation() { return _reppresentation; }
..........................................
class Population {
public:
vector<Chromosome> _chsome;
void computeFitnesses() {
//ni is wrong; I need something like a vector<int> to store every;
int ni = std::for_each( _chsome.begin(), _chsome.end(), Fitness() ).getCount();
}
class Fitness {
Gene _g;
int _count;
public:
Fitness() { }
void operator()(Chromosome g) {
_count = std::count_if( g.getReppresentation().begin(), g.getReppresentation().end(), fitness); //it doens't compile here on 'fitness'
}
bool fitness() { return _g.getAllele() == '1'; }
int getCount() { return _count; }
};
class Gene {
char _allele;
char getAllele() { return _allele; }
...................................
class Chromosome {
static const int _length = 5;
vector<Gene> _reppresentation;
vector<Gene>& getReppresentation() { return _reppresentation; }
..........................................
class Population {
public:
vector<Chromosome> _chsome;
void computeFitnesses() {
//ni is wrong; I need something like a vector<int> to store every;
int ni = std::for_each( _chsome.begin(), _chsome.end(), Fitness() ).getCount();
}
class Fitness {
Gene _g;
int _count;
public:
Fitness() { }
void operator()(Chromosome g) {
_count = std::count_if( g.getReppresentation().begin(), g.getReppresentation().end(), fitness); //it doens't compile here on 'fitness'
}
bool fitness() { return _g.getAllele() == '1'; }
int getCount() { return _count; }
};
To copy to clipboard, switch view to plain text mode
For each chromosome I need to return the number of '1'. Any helps, please?
Bookmarks