diff --git a/tools/yulPhaser/Population.cpp b/tools/yulPhaser/Population.cpp index 02d356bb1..dbd406613 100644 --- a/tools/yulPhaser/Population.cpp +++ b/tools/yulPhaser/Population.cpp @@ -148,9 +148,7 @@ void Population::doEvaluation() void Population::doSelection() { - assert(all_of(m_individuals.begin(), m_individuals.end(), [](auto& i){ return i.fitness.has_value(); })); - - sort(m_individuals.begin(), m_individuals.end(), isFitter); + m_individuals = sortedIndividuals(move(m_individuals)); randomizeWorstChromosomes(m_individuals, m_individuals.size() / 2); } @@ -179,3 +177,11 @@ vector Population::chromosomesToIndividuals( return individuals; } + +vector Population::sortedIndividuals(vector _individuals) +{ + assert(all_of(_individuals.begin(), _individuals.end(), [](auto& i){ return i.fitness.has_value(); })); + + sort(_individuals.begin(), _individuals.end(), isFitter); + return _individuals; +} diff --git a/tools/yulPhaser/Population.h b/tools/yulPhaser/Population.h index ec384ecc8..1e8a116b8 100644 --- a/tools/yulPhaser/Population.h +++ b/tools/yulPhaser/Population.h @@ -121,6 +121,7 @@ private: static std::vector chromosomesToIndividuals( std::vector _chromosomes ); + static std::vector sortedIndividuals(std::vector _individuals); Program m_program; std::vector m_individuals;