mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] Add options for selecting crossover operator used by the algorithms
This commit is contained in:
@@ -51,6 +51,8 @@ protected:
|
||||
/* mutationChance = */ 0.0,
|
||||
/* deletionChance = */ 0.0,
|
||||
/* additionChance = */ 0.0,
|
||||
/* CrossoverChoice = */ CrossoverChoice::SinglePoint,
|
||||
/* uniformCrossoverSwapChance= */ 0.5,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -113,6 +115,8 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_preserve_elite_and_regenerate_rest_o
|
||||
/* deletionVsAdditionChance = */ 1.0,
|
||||
/* percentGenesToRandomise = */ 0.0,
|
||||
/* percentGenesToAddOrDelete = */ 1.0,
|
||||
/* CrossoverChoice = */ CrossoverChoice::SinglePoint,
|
||||
/* uniformCrossoverSwapChance= */ 0.5,
|
||||
};
|
||||
GenerationalElitistWithExclusivePools algorithm(options);
|
||||
|
||||
@@ -133,6 +137,8 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_not_replace_elite_with_worse_individ
|
||||
/* deletionVsAdditionChance = */ 0.0,
|
||||
/* percentGenesToRandomise = */ 0.0,
|
||||
/* percentGenesToAddOrDelete = */ 1.0,
|
||||
/* CrossoverChoice = */ CrossoverChoice::SinglePoint,
|
||||
/* uniformCrossoverSwapChance= */ 0.5,
|
||||
};
|
||||
GenerationalElitistWithExclusivePools algorithm(options);
|
||||
|
||||
@@ -152,6 +158,8 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_generate_individuals_in_the_crossove
|
||||
/* deletionVsAdditionChance = */ 0.5,
|
||||
/* percentGenesToRandomise = */ 1.0,
|
||||
/* percentGenesToAddOrDelete = */ 1.0,
|
||||
/* CrossoverChoice = */ CrossoverChoice::SinglePoint,
|
||||
/* uniformCrossoverSwapChance= */ 0.5,
|
||||
};
|
||||
GenerationalElitistWithExclusivePools algorithm(options);
|
||||
|
||||
@@ -179,6 +187,8 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_generate_individuals_in_the_crossove
|
||||
/* deletionVsAdditionChance = */ 0.0,
|
||||
/* percentGenesToRandomise = */ 0.0,
|
||||
/* percentGenesToAddOrDelete = */ 0.0,
|
||||
/* CrossoverChoice = */ CrossoverChoice::SinglePoint,
|
||||
/* uniformCrossoverSwapChance= */ 0.5,
|
||||
};
|
||||
GenerationalElitistWithExclusivePools algorithm(options);
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ protected:
|
||||
/* algorithm = */ Algorithm::Random,
|
||||
/* minChromosomeLength = */ 50,
|
||||
/* maxChromosomeLength = */ 100,
|
||||
/* CrossoverChoice = */ CrossoverChoice::Uniform,
|
||||
/* uniformCrossoverSwapChance = */ 0.5,
|
||||
/* randomElitePoolSize = */ 0.5,
|
||||
/* gewepMutationPoolSize = */ 0.1,
|
||||
/* gewepCrossoverPoolSize = */ 0.1,
|
||||
@@ -121,6 +123,9 @@ BOOST_FIXTURE_TEST_CASE(build_should_select_the_right_algorithm_and_pass_the_opt
|
||||
|
||||
auto gewepAlgorithm = dynamic_cast<GenerationalElitistWithExclusivePools*>(algorithm2.get());
|
||||
BOOST_REQUIRE(gewepAlgorithm != nullptr);
|
||||
BOOST_TEST(gewepAlgorithm->options().crossover == m_options.crossover);
|
||||
BOOST_TEST(gewepAlgorithm->options().uniformCrossoverSwapChance.has_value());
|
||||
BOOST_TEST(gewepAlgorithm->options().uniformCrossoverSwapChance.value() == m_options.uniformCrossoverSwapChance);
|
||||
BOOST_TEST(gewepAlgorithm->options().mutationPoolSize == m_options.gewepMutationPoolSize);
|
||||
BOOST_TEST(gewepAlgorithm->options().crossoverPoolSize == m_options.gewepCrossoverPoolSize);
|
||||
BOOST_TEST(gewepAlgorithm->options().randomisationChance == m_options.gewepRandomisationChance);
|
||||
@@ -134,6 +139,8 @@ BOOST_FIXTURE_TEST_CASE(build_should_select_the_right_algorithm_and_pass_the_opt
|
||||
|
||||
auto classicAlgorithm = dynamic_cast<ClassicGeneticAlgorithm*>(algorithm3.get());
|
||||
BOOST_REQUIRE(classicAlgorithm != nullptr);
|
||||
BOOST_TEST(classicAlgorithm->options().uniformCrossoverSwapChance.has_value());
|
||||
BOOST_TEST(classicAlgorithm->options().uniformCrossoverSwapChance.value() == m_options.uniformCrossoverSwapChance);
|
||||
BOOST_TEST(classicAlgorithm->options().elitePoolSize == m_options.classicElitePoolSize);
|
||||
BOOST_TEST(classicAlgorithm->options().crossoverChance == m_options.classicCrossoverChance);
|
||||
BOOST_TEST(classicAlgorithm->options().mutationChance == m_options.classicMutationChance);
|
||||
|
||||
Reference in New Issue
Block a user