From d8e5f8f9653e6b6ee196136a9f978f15e49d9329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 21 Feb 2020 20:01:00 +0100 Subject: [PATCH] [yul-phaser] Add --rounds option --- tools/yulPhaser/Phaser.cpp | 14 +++++++++++++- tools/yulPhaser/Phaser.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/yulPhaser/Phaser.cpp b/tools/yulPhaser/Phaser.cpp index f02e942f7..3d45db1e8 100644 --- a/tools/yulPhaser/Phaser.cpp +++ b/tools/yulPhaser/Phaser.cpp @@ -185,6 +185,11 @@ Phaser::CommandLineDescription Phaser::buildCommandLineDescription() ("help", "Show help message and exit.") ("input-file", po::value()->required()->value_name(""), "Input file.") ("seed", po::value()->value_name(""), "Seed for the random number generator.") + ( + "rounds", + po::value()->value_name(""), + "The number of rounds after which the algorithm should stop. (default=no limit)." + ) ; keywordDescription.add(generalDescription); @@ -249,6 +254,13 @@ void Phaser::initialiseRNG(po::variables_map const& _arguments) cout << "Random seed: " << seed << endl; } +AlgorithmRunner::Options Phaser::buildAlgorithmRunnerOptions(po::variables_map const& _arguments) +{ + return { + _arguments.count("rounds") > 0 ? static_cast>(_arguments["rounds"].as()) : nullopt + }; +} + void Phaser::runAlgorithm(po::variables_map const& _arguments) { auto programOptions = ProgramFactory::Options::fromCommandLine(_arguments); @@ -266,6 +278,6 @@ void Phaser::runAlgorithm(po::variables_map const& _arguments) PopulationFactory::MaxChromosomeLength ); - AlgorithmRunner algorithmRunner(population, AlgorithmRunner::Options{}, cout); + AlgorithmRunner algorithmRunner(population, buildAlgorithmRunnerOptions(_arguments), cout); algorithmRunner.run(*geneticAlgorithm); } diff --git a/tools/yulPhaser/Phaser.h b/tools/yulPhaser/Phaser.h index 20d9ace25..ac6f70def 100644 --- a/tools/yulPhaser/Phaser.h +++ b/tools/yulPhaser/Phaser.h @@ -21,6 +21,8 @@ #pragma once +#include + #include #include @@ -147,6 +149,7 @@ private: static CommandLineDescription buildCommandLineDescription(); static std::optional parseCommandLine(int _argc, char** _argv); static void initialiseRNG(boost::program_options::variables_map const& _arguments); + static AlgorithmRunner::Options buildAlgorithmRunnerOptions(boost::program_options::variables_map const& _arguments); static void runAlgorithm(boost::program_options::variables_map const& _arguments); };