mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] Add --population option
This commit is contained in:
parent
af090876b5
commit
5e00b57e02
@ -114,6 +114,9 @@ unique_ptr<FitnessMetric> FitnessMetricFactory::build(
|
|||||||
PopulationFactory::Options PopulationFactory::Options::fromCommandLine(po::variables_map const& _arguments)
|
PopulationFactory::Options PopulationFactory::Options::fromCommandLine(po::variables_map const& _arguments)
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
|
_arguments.count("population") > 0 ?
|
||||||
|
_arguments["population"].as<vector<string>>() :
|
||||||
|
vector<string>{},
|
||||||
_arguments.count("random-population") > 0 ?
|
_arguments.count("random-population") > 0 ?
|
||||||
_arguments["random-population"].as<vector<size_t>>() :
|
_arguments["random-population"].as<vector<size_t>>() :
|
||||||
vector<size_t>{},
|
vector<size_t>{},
|
||||||
@ -125,7 +128,7 @@ Population PopulationFactory::build(
|
|||||||
shared_ptr<FitnessMetric> _fitnessMetric
|
shared_ptr<FitnessMetric> _fitnessMetric
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Population population(_fitnessMetric, vector<Chromosome>{});
|
Population population = buildFromStrings(_options.population, _fitnessMetric);
|
||||||
|
|
||||||
size_t combinedSize = 0;
|
size_t combinedSize = 0;
|
||||||
for (size_t populationSize: _options.randomPopulation)
|
for (size_t populationSize: _options.randomPopulation)
|
||||||
@ -139,6 +142,17 @@ Population PopulationFactory::build(
|
|||||||
return population;
|
return population;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Population PopulationFactory::buildFromStrings(
|
||||||
|
vector<string> const& _geneSequences,
|
||||||
|
shared_ptr<FitnessMetric> _fitnessMetric
|
||||||
|
)
|
||||||
|
{
|
||||||
|
vector<Chromosome> chromosomes;
|
||||||
|
for (string const& geneSequence: _geneSequences)
|
||||||
|
chromosomes.emplace_back(geneSequence);
|
||||||
|
|
||||||
|
return Population(move(_fitnessMetric), move(chromosomes));
|
||||||
|
}
|
||||||
|
|
||||||
Population PopulationFactory::buildRandom(
|
Population PopulationFactory::buildRandom(
|
||||||
size_t _populationSize,
|
size_t _populationSize,
|
||||||
@ -235,6 +249,13 @@ Phaser::CommandLineDescription Phaser::buildCommandLineDescription()
|
|||||||
|
|
||||||
po::options_description populationDescription("POPULATION", lineLength, minDescriptionLength);
|
po::options_description populationDescription("POPULATION", lineLength, minDescriptionLength);
|
||||||
populationDescription.add_options()
|
populationDescription.add_options()
|
||||||
|
(
|
||||||
|
"population",
|
||||||
|
po::value<vector<string>>()->multitoken()->value_name("<CHROMOSOMES>"),
|
||||||
|
"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",
|
"random-population",
|
||||||
po::value<vector<size_t>>()->value_name("<SIZE>"),
|
po::value<vector<size_t>>()->value_name("<SIZE>"),
|
||||||
|
@ -106,6 +106,7 @@ public:
|
|||||||
|
|
||||||
struct Options
|
struct Options
|
||||||
{
|
{
|
||||||
|
std::vector<std::string> population;
|
||||||
std::vector<size_t> randomPopulation;
|
std::vector<size_t> randomPopulation;
|
||||||
|
|
||||||
static Options fromCommandLine(boost::program_options::variables_map const& _arguments);
|
static Options fromCommandLine(boost::program_options::variables_map const& _arguments);
|
||||||
@ -115,6 +116,10 @@ public:
|
|||||||
Options const& _options,
|
Options const& _options,
|
||||||
std::shared_ptr<FitnessMetric> _fitnessMetric
|
std::shared_ptr<FitnessMetric> _fitnessMetric
|
||||||
);
|
);
|
||||||
|
static Population buildFromStrings(
|
||||||
|
std::vector<std::string> const& _geneSequences,
|
||||||
|
std::shared_ptr<FitnessMetric> _fitnessMetric
|
||||||
|
);
|
||||||
static Population buildRandom(
|
static Population buildRandom(
|
||||||
size_t _populationSize,
|
size_t _populationSize,
|
||||||
std::shared_ptr<FitnessMetric> _fitnessMetric
|
std::shared_ptr<FitnessMetric> _fitnessMetric
|
||||||
|
Loading…
Reference in New Issue
Block a user