diff --git a/eo/src/utils/selectors.h b/eo/src/utils/selectors.h index 349bf7cc7..9d860873e 100644 --- a/eo/src/utils/selectors.h +++ b/eo/src/utils/selectors.h @@ -132,7 +132,11 @@ double sum_fitness(const eoPop& _pop, std::pair& _minmax) template It roulette_wheel(It _begin, It _end, double total, eoRng& _gen = rng) { + float roulette = _gen.uniform(total); + + if (roulette == 0.0) // covers the case where total==0.0 + return _min + _gen.random(_end - _min); // uniform choice It i = _begin; @@ -149,6 +153,9 @@ const EOT& roulette_wheel(const eoPop& _pop, double total, eoRng& _gen = rn { float roulette = _gen.uniform(total); + if (roulette == 0.0) // covers the case where total==0.0 + return _pop[_gen.random(_pop.size())]; // uniform choice + eoPop::const_iterator i = _pop.begin(); while (roulette > 0.0) @@ -164,6 +171,9 @@ EOT& roulette_wheel(eoPop& _pop, double total, eoRng& _gen = rng) { float roulette = _gen.uniform(total); + if (roulette == 0.0) // covers the case where total==0.0 + return _pop[_gen.random(_pop.size())]; // uniform choice + eoPop::iterator i = _pop.begin(); while (roulette > 0.0)