eoLottery finished

This commit is contained in:
gustavo 1999-02-05 16:34:00 +00:00
commit 5247c976ce
3 changed files with 11 additions and 11 deletions

View file

@ -13,8 +13,7 @@
//-----------------------------------------------------------------------------
/// eoLottery: a selection method.
/// requires that the fitness type of the chromosome inherits from eoFitness
/// or have a cast to float implemented
/// requires Chrom::Fitness to be float castable
//-----------------------------------------------------------------------------
template<class Chrom> class eoLottery: public eoSelect<Chrom>
@ -28,11 +27,11 @@ template<class Chrom> class eoLottery: public eoSelect<Chrom>
{
// scores of chromosomes
vector<float> score(pop.size());
// calculates accumulated scores for chromosomes
for (unsigned i = 0; i < pop.size(); i++)
score[i] = pop[i].fitness();
score[i] = static_cast<float>(pop[i].fitness());
float sum = accumulate(score.begin(), score.end(), MINFLOAT);
transform(score.begin(), score.end(), score.begin(),
bind2nd(divides<float>(), sum));