[yul-phaser] Population: Equality operators for populations and individuals

This commit is contained in:
Kamil Śliwak 2020-02-11 11:25:00 +01:00
parent d9c5e2dc9f
commit 31d8d5930a
2 changed files with 13 additions and 0 deletions

View File

@ -125,6 +125,13 @@ Population operator+(Population _a, Population _b)
return Population(_a.m_program, move(_a.m_individuals) + move(_b.m_individuals));
}
bool Population::operator==(Population const& _other) const
{
// TODO: Comparing programs is pretty heavy but it's just a stopgap. It will soon be replaced
// by a comparison of fitness metric associated with the population (once metrics are introduced).
return m_individuals == _other.m_individuals && toString(m_program) == toString(_other.m_program);
}
ostream& phaser::operator<<(ostream& _stream, Population const& _population)
{
auto individual = _population.m_individuals.begin();

View File

@ -48,6 +48,9 @@ struct Individual
Chromosome chromosome;
std::optional<size_t> fitness = std::nullopt;
bool operator==(Individual const& _other) const { return fitness == _other.fitness && chromosome == _other.chromosome; }
bool operator!=(Individual const& _other) const { return !(*this == _other); }
friend std::ostream& operator<<(std::ostream& _stream, Individual const& _individual);
};
@ -93,6 +96,9 @@ public:
static size_t binomialChromosomeLength(size_t _max) { return SimulationRNG::binomialInt(_max, 0.5); }
static size_t measureFitness(Chromosome const& _chromosome, Program const& _program);
bool operator==(Population const& _other) const;
bool operator!=(Population const& _other) const { return !(*this == _other); }
friend std::ostream& operator<<(std::ostream& _stream, Population const& _population);
private: