[yul-phaser] Population: Add combine()

This commit is contained in:
Kamil Śliwak 2020-03-11 02:14:30 +01:00
parent ef8d0888af
commit 8c86a4983d
3 changed files with 14 additions and 0 deletions

View File

@ -364,6 +364,14 @@ BOOST_FIXTURE_TEST_CASE(symmetricCrossoverWithRemainder_should_return_empty_popu
); );
} }
BOOST_FIXTURE_TEST_CASE(combine_should_add_two_populations_from_a_pair, PopulationFixture)
{
Population population1(m_fitnessMetric, {Chromosome("aa"), Chromosome("hh")});
Population population2(m_fitnessMetric, {Chromosome("gg"), Chromosome("cc")});
BOOST_TEST(Population::combine({population1, population2}) == population1 + population2);
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

View File

@ -163,6 +163,11 @@ Population operator+(Population _a, Population _b)
} }
Population Population::combine(std::tuple<Population, Population> _populationPair)
{
return get<0>(_populationPair) + get<1>(_populationPair);
}
bool Population::operator==(Population const& _other) const bool Population::operator==(Population const& _other) const
{ {
// We consider populations identical only if they share the same exact instance of the metric. // We consider populations identical only if they share the same exact instance of the metric.

View File

@ -106,6 +106,7 @@ public:
) const; ) const;
friend Population operator+(Population _a, Population _b); friend Population operator+(Population _a, Population _b);
static Population combine(std::tuple<Population, Population> _populationPair);
std::shared_ptr<FitnessMetric> fitnessMetric() { return m_fitnessMetric; } std::shared_ptr<FitnessMetric> fitnessMetric() { return m_fitnessMetric; }
std::vector<Individual> const& individuals() const { return m_individuals; } std::vector<Individual> const& individuals() const { return m_individuals; }