From df1ebb94dd025b7d217f27f7e11d312d69afbcc9 Mon Sep 17 00:00:00 2001 From: Alessandro Sidero <75628365+Alessandro624@users.noreply.github.com> Date: Tue, 15 Apr 2025 00:23:31 +0200 Subject: [PATCH] fix: used an unordered_map instead of vactor to save indexes --- eo/src/eoRanking.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/eo/src/eoRanking.h b/eo/src/eoRanking.h index 1a8bfe3ed..ef06d6763 100644 --- a/eo/src/eoRanking.h +++ b/eo/src/eoRanking.h @@ -148,7 +148,6 @@ public: */ virtual void operator()(const eoPop &_pop) { - unsigned pSize = _pop.size(); if (pSize <= 1) @@ -170,16 +169,19 @@ public: std::vector rank; _pop.sort(rank); - // vector of indices sorted by fitness - std::vector indices(pSize); - for (size_t i = 0; i < pSize; ++i) - indices[i] = i; + // map of indices for the population + std::unordered_map indexMap; + for (unsigned i = 0; i < pSize; ++i) + { + indexMap[&_pop[i]] = i; + } if (exponent == 1.0) // no need for exponetial then (linear case) { for (unsigned i = 0; i < pSize; i++) { - int which = indices[i]; + const EOT *indiv = rank[i]; + int which = indexMap[indiv]; value()[which] = cached_alpha * (pSize - i) + cached_beta; } } @@ -187,7 +189,8 @@ public: { for (unsigned i = 0; i < pSize; i++) { - int which = indices[i]; + const EOT *indiv = rank[i]; + int which = indexMap[indiv]; // value in in [0,1] double tmp = ((double)(pSize - i)) / pSize; // to the exponent, and back to [m,M]