changes on eoLottery
This commit is contained in:
parent
b5cb78b70f
commit
a44af3e7f4
1 changed files with 10 additions and 12 deletions
|
|
@ -7,10 +7,14 @@
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <eo>
|
||||
#include <values.h> // MINFLOAT
|
||||
#include <numeric> // accumulate
|
||||
#include <eo> // eoPop eoSelect
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoLottery
|
||||
/// eoLottery: a selection method.
|
||||
/// requires that the fitness type of the chromosome inherits from eoFitness
|
||||
/// or have a cast to float implemented
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template<class Chrom> class eoLottery: public eoSelect<Chrom>
|
||||
|
|
@ -26,15 +30,9 @@ template<class Chrom> class eoLottery: public eoSelect<Chrom>
|
|||
vector<float> score(pop.size());
|
||||
|
||||
// calculates accumulated scores for chromosomes
|
||||
|
||||
transform(pop.begin(), pop.end(), score.begin(), fitness);
|
||||
|
||||
for (unsigned i = 0; i < pop.size(); i++)
|
||||
score[i] = pop[i].fitness();
|
||||
|
||||
|
||||
|
||||
|
||||
float sum = accumulate(score.begin(), score.end(), MINFLOAT);
|
||||
transform(score.begin(), score.end(), score.begin(),
|
||||
bind2nd(divides<float>(), sum));
|
||||
|
|
|
|||
Reference in a new issue