mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] Population: Add select() method
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -39,6 +39,8 @@ solidity::phaser::Population operator+(solidity::phaser::Population _a, solidity
|
||||
namespace solidity::phaser
|
||||
{
|
||||
|
||||
class Selection;
|
||||
|
||||
/**
|
||||
* Information describing the state of an individual member of the population during the course
|
||||
* of the genetic algorithm.
|
||||
@@ -102,6 +104,7 @@ public:
|
||||
);
|
||||
|
||||
void run(std::optional<size_t> _numRounds, std::ostream& _outputStream);
|
||||
Population select(Selection const& _selection) const;
|
||||
friend Population (::operator+)(Population _a, Population _b);
|
||||
|
||||
std::shared_ptr<FitnessMetric const> fitnessMetric() const { return m_fitnessMetric; }
|
||||
|
||||
Reference in New Issue
Block a user