Skip to content

Commit

Permalink
fix(moRndVectorVNSelection): use shuffle for modern compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
jdreo committed Sep 5, 2024
1 parent 732fe09 commit 51be7e3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions mo/src/neighborhood/moRndVectorVNSelection.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class moRndVectorVNSelection: public moVectorVNSelection<EOT>
/**
* Default constructor with first search heuristics
*
* @param _firstLS first local search
* @param _firstLS first local search
* @param _firstShake first heuristic which perturbs the solution
* @param _cycle when true, the first heuristics follows the last ones. Otherwise the search stop.
*/
Expand All @@ -67,7 +67,7 @@ class moRndVectorVNSelection: public moVectorVNSelection<EOT>
}

/**
* test if there is still some heuristics
* test if there is still some heuristics
*
* @param _solution the current solution
* @return true if there is some heuristics
Expand All @@ -83,11 +83,17 @@ class moRndVectorVNSelection: public moVectorVNSelection<EOT>
*/
virtual void init(EOT& /*_solution*/) {
if(order.size() == 0)
for(unsigned int i = 0; i < LSvector.size(); i++)
order.push_back(i);

for(unsigned int i = 0; i < LSvector.size(); i++) {
order.push_back(i); }

#if __cplusplus >= 201103L
std::random_device rd;
std::mt19937 gen(rd());
std::shuffle(order.begin(), order.end(), gen);
#else
UF_random_generator<unsigned int> gen(order.size());
std::random_shuffle(order.begin(), order.end(), gen);
#endif

currentOrder = 0;
current = order[currentOrder];
Expand Down

0 comments on commit 51be7e3

Please sign in to comment.