[yul-phaser] Population: Add select() method

This commit is contained in:
cameel
2020-02-25 15:25:16 +01:00
committed by Kamil Śliwak
parent 83b8ab8012
commit 4665b7a7e4
3 changed files with 49 additions and 0 deletions
+10
View File
@@ -17,6 +17,7 @@
#include <tools/yulPhaser/Population.h>
#include <tools/yulPhaser/Selections.h>
#include <libsolutil/CommonData.h>
#include <libsolutil/CommonIO.h>
@@ -95,6 +96,15 @@ void Population::run(optional<size_t> _numRounds, ostream& _outputStream)
}
}
Population Population::select(Selection const& _selection) const
{
vector<Individual> selectedIndividuals;
for (size_t i: _selection.materialise(m_individuals.size()))
selectedIndividuals.emplace_back(m_individuals[i]);
return Population(m_fitnessMetric, selectedIndividuals);
}
Population operator+(Population _a, Population _b)
{
// This operator is meant to be used only with populations sharing the same metric (and, to make