From 8c86a4983d70eda377db17d3f4833698052c342b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Wed, 11 Mar 2020 02:14:30 +0100 Subject: [PATCH] [yul-phaser] Population: Add combine() --- test/yulPhaser/Population.cpp | 8 ++++++++ tools/yulPhaser/Population.cpp | 5 +++++ tools/yulPhaser/Population.h | 1 + 3 files changed, 14 insertions(+) diff --git a/test/yulPhaser/Population.cpp b/test/yulPhaser/Population.cpp index 12555845c..1657e97c9 100644 --- a/test/yulPhaser/Population.cpp +++ b/test/yulPhaser/Population.cpp @@ -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() diff --git a/tools/yulPhaser/Population.cpp b/tools/yulPhaser/Population.cpp index acdae1eb7..1b846122e 100644 --- a/tools/yulPhaser/Population.cpp +++ b/tools/yulPhaser/Population.cpp @@ -163,6 +163,11 @@ Population operator+(Population _a, Population _b) } +Population Population::combine(std::tuple _populationPair) +{ + return get<0>(_populationPair) + get<1>(_populationPair); +} + bool Population::operator==(Population const& _other) const { // We consider populations identical only if they share the same exact instance of the metric. diff --git a/tools/yulPhaser/Population.h b/tools/yulPhaser/Population.h index 2d79dfef2..c405f702c 100644 --- a/tools/yulPhaser/Population.h +++ b/tools/yulPhaser/Population.h @@ -106,6 +106,7 @@ public: ) const; friend Population operator+(Population _a, Population _b); + static Population combine(std::tuple _populationPair); std::shared_ptr fitnessMetric() { return m_fitnessMetric; } std::vector const& individuals() const { return m_individuals; }