Skip to content

Commit

Permalink
Another std::shuffle implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri Rusin committed May 7, 2024
1 parent e5f342d commit 6427347
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 129 deletions.
12 changes: 11 additions & 1 deletion include/ioh/problem/dynamic_bin_val/dynamic_bin_val_ranking.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@

namespace ioh::problem
{
template <typename RandomGenerator>
void portable_shuffle(std::vector<int>& array, RandomGenerator& generator) {
for (size_t i = array.size() - 1; i > 0; --i) {
std::uniform_int_distribution<size_t> distribution(0, i);
size_t j = distribution(generator);
std::swap(array[i], array[j]);
}
}

/**
* @class DynamicBinValRanking
* @brief Represents dynamic binary value problems in Iterative Optimization Heuristics (IOH).
Expand Down Expand Up @@ -67,7 +76,8 @@ namespace ioh::problem

int step() override
{
std::shuffle(comparison_ordering.begin(), comparison_ordering.end(), this->random_generator);
// using std::shuffle results in different behaviour on Windows versus. on Ubuntu.
portable_shuffle(comparison_ordering, this->random_generator);
this->timestep += 1;
return this->timestep;
}
Expand Down
Loading

0 comments on commit 6427347

Please sign in to comment.