From 5e00b57e02a435cb752502d11bc50b306aa97f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Sat, 22 Feb 2020 00:01:06 +0100 Subject: [PATCH] [yul-phaser] Add --population option --- tools/yulPhaser/Phaser.cpp | 23 ++++++++++++++++++++++- tools/yulPhaser/Phaser.h | 5 +++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tools/yulPhaser/Phaser.cpp b/tools/yulPhaser/Phaser.cpp index 768088e49..8c5fcbc26 100644 --- a/tools/yulPhaser/Phaser.cpp +++ b/tools/yulPhaser/Phaser.cpp @@ -114,6 +114,9 @@ unique_ptr FitnessMetricFactory::build( PopulationFactory::Options PopulationFactory::Options::fromCommandLine(po::variables_map const& _arguments) { return { + _arguments.count("population") > 0 ? + _arguments["population"].as>() : + vector{}, _arguments.count("random-population") > 0 ? _arguments["random-population"].as>() : vector{}, @@ -125,7 +128,7 @@ Population PopulationFactory::build( shared_ptr _fitnessMetric ) { - Population population(_fitnessMetric, vector{}); + Population population = buildFromStrings(_options.population, _fitnessMetric); size_t combinedSize = 0; for (size_t populationSize: _options.randomPopulation) @@ -139,6 +142,17 @@ Population PopulationFactory::build( return population; } +Population PopulationFactory::buildFromStrings( + vector const& _geneSequences, + shared_ptr _fitnessMetric +) +{ + vector chromosomes; + for (string const& geneSequence: _geneSequences) + chromosomes.emplace_back(geneSequence); + + return Population(move(_fitnessMetric), move(chromosomes)); +} Population PopulationFactory::buildRandom( size_t _populationSize, @@ -235,6 +249,13 @@ Phaser::CommandLineDescription Phaser::buildCommandLineDescription() po::options_description populationDescription("POPULATION", lineLength, minDescriptionLength); populationDescription.add_options() + ( + "population", + po::value>()->multitoken()->value_name(""), + "List of chromosomes to be included in the initial population. " + "You can specify multiple values separated with spaces or invoke the option multiple times " + "and all the values will be included." + ) ( "random-population", po::value>()->value_name(""), diff --git a/tools/yulPhaser/Phaser.h b/tools/yulPhaser/Phaser.h index 4df0109f7..a12ccd87a 100644 --- a/tools/yulPhaser/Phaser.h +++ b/tools/yulPhaser/Phaser.h @@ -106,6 +106,7 @@ public: struct Options { + std::vector population; std::vector randomPopulation; static Options fromCommandLine(boost::program_options::variables_map const& _arguments); @@ -115,6 +116,10 @@ public: Options const& _options, std::shared_ptr _fitnessMetric ); + static Population buildFromStrings( + std::vector const& _geneSequences, + std::shared_ptr _fitnessMetric + ); static Population buildRandom( size_t _populationSize, std::shared_ptr _fitnessMetric