mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] Add --relative-metric-scale option
This commit is contained in:
parent
8e64c5c6f0
commit
01050940fd
@ -62,6 +62,7 @@ protected:
|
||||
Program m_program = get<Program>(Program::load(m_sourceStream));
|
||||
FitnessMetricFactory::Options m_options = {
|
||||
/* metric = */ MetricChoice::CodeSize,
|
||||
/* relativeMetricScale = */ 5,
|
||||
/* chromosomeRepetitions = */ 1,
|
||||
};
|
||||
};
|
||||
@ -163,6 +164,18 @@ BOOST_FIXTURE_TEST_CASE(build_should_respect_chromosome_repetitions_option, Fitn
|
||||
BOOST_TEST(programSizeMetric->repetitionCount() == m_options.chromosomeRepetitions);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(build_should_set_relative_metric_scale, FitnessMetricFactoryFixture)
|
||||
{
|
||||
m_options.metric = MetricChoice::RelativeCodeSize;
|
||||
m_options.relativeMetricScale = 10;
|
||||
unique_ptr<FitnessMetric> metric = FitnessMetricFactory::build(m_options, m_program);
|
||||
BOOST_REQUIRE(metric != nullptr);
|
||||
|
||||
auto relativeProgramSizeMetric = dynamic_cast<RelativeProgramSize*>(metric.get());
|
||||
BOOST_REQUIRE(relativeProgramSizeMetric != nullptr);
|
||||
BOOST_TEST(relativeProgramSizeMetric->fixedPointPrecision() == m_options.relativeMetricScale);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
BOOST_AUTO_TEST_SUITE(PopulationFactoryTest)
|
||||
|
||||
|
@ -139,6 +139,7 @@ FitnessMetricFactory::Options FitnessMetricFactory::Options::fromCommandLine(po:
|
||||
{
|
||||
return {
|
||||
_arguments["metric"].as<MetricChoice>(),
|
||||
_arguments["relative-metric-scale"].as<size_t>(),
|
||||
_arguments["chromosome-repetitions"].as<size_t>(),
|
||||
};
|
||||
}
|
||||
@ -158,7 +159,7 @@ unique_ptr<FitnessMetric> FitnessMetricFactory::build(
|
||||
case MetricChoice::RelativeCodeSize:
|
||||
return make_unique<RelativeProgramSize>(
|
||||
move(_program),
|
||||
3,
|
||||
_options.relativeMetricScale,
|
||||
_options.chromosomeRepetitions
|
||||
);
|
||||
default:
|
||||
@ -421,6 +422,18 @@ Phaser::CommandLineDescription Phaser::buildCommandLineDescription()
|
||||
po::value<MetricChoice>()->value_name("<NAME>")->default_value(MetricChoice::CodeSize),
|
||||
"Metric used to evaluate the fitness of a chromosome."
|
||||
)
|
||||
(
|
||||
"relative-metric-scale",
|
||||
po::value<size_t>()->value_name("<EXPONENT>")->default_value(3),
|
||||
"Scaling factor for values produced by relative fitness metrics. \n"
|
||||
"Since all metrics must produce integer values, the fractional part of the result is discarded. "
|
||||
"To keep the numbers meaningful, a relative metric multiples its values by a scaling factor "
|
||||
"and this option specifies the exponent of this factor. "
|
||||
"For example with value of 3 the factor is 10^3 = 1000 and the metric will return "
|
||||
"500 to represent 0.5, 1000 for 1.0, 2000 for 2.0 and so on. "
|
||||
"Using a bigger factor allows discerning smaller relative differences between chromosomes "
|
||||
"but makes the numbers less readable and may also lose precision if the numbers are very large."
|
||||
)
|
||||
(
|
||||
"chromosome-repetitions",
|
||||
po::value<size_t>()->value_name("<COUNT>")->default_value(1),
|
||||
|
@ -100,6 +100,7 @@ public:
|
||||
struct Options
|
||||
{
|
||||
MetricChoice metric;
|
||||
size_t relativeMetricScale;
|
||||
size_t chromosomeRepetitions;
|
||||
|
||||
static Options fromCommandLine(boost::program_options::variables_map const& _arguments);
|
||||
|
Loading…
Reference in New Issue
Block a user