From 41f36f421db46bbfde1e1a754bbb37267d768c96 Mon Sep 17 00:00:00 2001 From: cameel Date: Wed, 5 Feb 2020 15:15:17 +0100 Subject: [PATCH] [yul-phaser] Population: Extract conversion from chromosomes to individuals into a separate function --- tools/yulPhaser/Population.cpp | 18 +++++++++++------- tools/yulPhaser/Population.h | 9 ++++++++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/tools/yulPhaser/Population.cpp b/tools/yulPhaser/Population.cpp index a0b64999b..02d356bb1 100644 --- a/tools/yulPhaser/Population.cpp +++ b/tools/yulPhaser/Population.cpp @@ -63,13 +63,6 @@ bool phaser::isFitter(Individual const& a, Individual const& b) ); } -Population::Population(Program _program, vector const& _chromosomes): - m_program{move(_program)} -{ - for (auto const& chromosome: _chromosomes) - m_individuals.push_back({chromosome}); -} - Population Population::makeRandom( Program _program, size_t _size, @@ -175,3 +168,14 @@ void Population::randomizeWorstChromosomes( *individual = {Chromosome::makeRandom(binomialChromosomeLength(MaxChromosomeLength))}; } } + +vector Population::chromosomesToIndividuals( + vector _chromosomes +) +{ + vector individuals; + for (auto& chromosome: _chromosomes) + individuals.push_back({move(chromosome)}); + + return individuals; +} diff --git a/tools/yulPhaser/Population.h b/tools/yulPhaser/Population.h index 466c8f6f7..ec384ecc8 100644 --- a/tools/yulPhaser/Population.h +++ b/tools/yulPhaser/Population.h @@ -73,7 +73,11 @@ class Population public: static constexpr size_t MaxChromosomeLength = 30; - explicit Population(Program _program, std::vector const& _chromosomes = {}); + explicit Population(Program _program, std::vector _chromosomes = {}): + Population( + std::move(_program), + chromosomesToIndividuals(std::move(_chromosomes)) + ) {} static Population makeRandom( Program _program, @@ -114,6 +118,9 @@ private: std::vector& _individuals, size_t _count ); + static std::vector chromosomesToIndividuals( + std::vector _chromosomes + ); Program m_program; std::vector m_individuals;