Hello,

I need to do something like this (that doens't compile); but anyway It's a bit wrong:
Qt Code:
  1. class Gene {
  2. char _allele;
  3. char getAllele() { return _allele; }
  4. ...................................
  5. class Chromosome {
  6. static const int _length = 5;
  7. vector<Gene> _reppresentation;
  8. vector<Gene>& getReppresentation() { return _reppresentation; }
  9. ..........................................
  10.  
  11. class Population {
  12. public:
  13. vector<Chromosome> _chsome;
  14. void computeFitnesses() {
  15. //ni is wrong; I need something like a vector<int> to store every;
  16. int ni = std::for_each( _chsome.begin(), _chsome.end(), Fitness() ).getCount();
  17. }
  18.  
  19. class Fitness {
  20. Gene _g;
  21. int _count;
  22. public:
  23. Fitness() { }
  24. void operator()(Chromosome g) {
  25. _count = std::count_if( g.getReppresentation().begin(), g.getReppresentation().end(), fitness); //it doens't compile here on 'fitness'
  26.  
  27. }
  28. bool fitness() { return _g.getAllele() == '1'; }
  29. int getCount() { return _count; }
  30. };
To copy to clipboard, switch view to plain text mode 
For each chromosome I need to return the number of '1'. Any helps, please?