[yul-phaser] main: Add --seed option

This commit is contained in:
Kamil Śliwak 2020-02-12 11:49:09 +01:00
parent f29d3655f7
commit 2f67302ffc

View File

@ -18,6 +18,7 @@
#include <tools/yulPhaser/Exceptions.h> #include <tools/yulPhaser/Exceptions.h>
#include <tools/yulPhaser/Population.h> #include <tools/yulPhaser/Population.h>
#include <tools/yulPhaser/Program.h> #include <tools/yulPhaser/Program.h>
#include <tools/yulPhaser/SimulationRNG.h>
#include <libsolutil/Assertions.h> #include <libsolutil/Assertions.h>
#include <libsolutil/CommonIO.h> #include <libsolutil/CommonIO.h>
@ -45,6 +46,19 @@ struct CommandLineParsingResult
po::variables_map arguments; po::variables_map arguments;
}; };
void initializeRNG(po::variables_map const& arguments)
{
uint32_t seed;
if (arguments.count("seed") > 0)
seed = arguments["seed"].as<uint32_t>();
else
seed = SimulationRNG::generateSeed();
SimulationRNG::reset(seed);
cout << "Random seed: " << seed << endl;
}
CharStream loadSource(string const& _sourcePath) CharStream loadSource(string const& _sourcePath)
{ {
assertThrow(boost::filesystem::exists(_sourcePath), InvalidProgram, "Source file does not exist"); assertThrow(boost::filesystem::exists(_sourcePath), InvalidProgram, "Source file does not exist");
@ -79,6 +93,7 @@ CommandLineParsingResult parseCommandLine(int argc, char** argv)
description.add_options() description.add_options()
("help", "Show help message and exit.") ("help", "Show help message and exit.")
("input-file", po::value<string>()->required(), "Input file") ("input-file", po::value<string>()->required(), "Input file")
("seed", po::value<uint32_t>(), "Seed for the random number generator")
; ;
po::positional_options_description positionalDescription; po::positional_options_description positionalDescription;
@ -121,6 +136,8 @@ int main(int argc, char** argv)
if (parsingResult.exitCode != 0) if (parsingResult.exitCode != 0)
return parsingResult.exitCode; return parsingResult.exitCode;
initializeRNG(parsingResult.arguments);
try try
{ {
runAlgorithm(parsingResult.arguments["input-file"].as<string>()); runAlgorithm(parsingResult.arguments["input-file"].as<string>());