From 43b5effcdb9acb5c021303c9ea6276d10206e9e9 Mon Sep 17 00:00:00 2001 From: maartenkeijzer Date: Wed, 4 Jun 2003 11:50:48 +0000 Subject: [PATCH] added shuffle --- eo/src/eoStochasticUniversalSelect.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/eo/src/eoStochasticUniversalSelect.h b/eo/src/eoStochasticUniversalSelect.h index d9ec16ef..ac64f149 100755 --- a/eo/src/eoStochasticUniversalSelect.h +++ b/eo/src/eoStochasticUniversalSelect.h @@ -31,6 +31,8 @@ #include #include +#include +#include //----------------------------------------------------------------------------- /** eoStochasticUniversalSelect: select an individual proportional to her stored fitness @@ -80,6 +82,11 @@ public: i = 0; } } + // shuffle + for (int i = indices.size() - 1; i > 0; --i) { + int j = rng.random(i+1); + swap(indices[i], indices[j]); + } } /** do the selection,