fix(rnd): use STL's rand gen for shuffles

Previous implementation used Paradiseo's own random generator system,
now superseeded by the STL's one.
This commit is contained in:
Johann Dreo 2024-08-19 11:02:15 +02:00
commit 6f7d505a2a
4 changed files with 25 additions and 19 deletions

View file

@ -29,11 +29,12 @@
#include <algorithm>
#include <cassert>
#include <random>
#include "eoOp.h"
#include "eoSTLFunctor.h"
#include "utils/eoRndGenerators.h"
#include "utils/rnd_generators.h" // for shuffle method
// #include "utils/rnd_generators.h" // for shuffle method
#include "eoExceptions.h"
@ -197,7 +198,8 @@ class eoInitPermutation: public eoInit<EOT> // FIXME inherit from eoInitWithDim
chrom[idx] = idx+startFrom;
}
UF_random_generator<unsigned int> gen(chrom.size());
std::random_device rd;
std::mt19937 gen(rd());
std::shuffle(chrom.begin(), chrom.end(), gen);
chrom.invalidate();
}

View file

@ -45,7 +45,7 @@ Authors:
#include "eoOp.h" // for eoInit
#include "eoPersistent.h"
#include "eoInit.h"
#include "utils/rnd_generators.h" // for shuffle method
// #include "utils/rnd_generators.h" // for shuffle method
#include "eoExceptions.h"
/** A std::vector of EO object, to be used in all algorithms

View file

@ -124,6 +124,7 @@ inline bool random_generator<bool>::operator()(void)
function (see eoPop::shuffle): its operator() takes an unsigned argument m
and must return an unsigned uniformly distributed in [0,m}
*/
// FIXME this is probably deprecated by the new STL way of managing random generators.
template <class T = uint32_t>
class UF_random_generator
{
@ -134,11 +135,11 @@ class UF_random_generator
: _max(max), _random(_rng)
{}
T operator()() { return _random.random(_max); }
T operator()(T m) { return _random.random(m); }
T operator()() const { return _random.random(_max); }
T operator()(T m) const { return _random.random(m); }
T min() { return 0; }
T max() { return _max; }
T min() const { return 0; }
T max() const { return _max; }
private :
T _max;