mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] GeneticAlgorithms: Add methods for selecting a crossover operator
This commit is contained in:
parent
1ada2a52fb
commit
ad89b477c8
@ -21,8 +21,47 @@
|
||||
#include <tools/yulPhaser/PairSelections.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity;
|
||||
using namespace solidity::phaser;
|
||||
|
||||
function<Crossover> phaser::buildCrossoverOperator(
|
||||
CrossoverChoice _choice,
|
||||
optional<double> _uniformCrossoverSwapChance
|
||||
)
|
||||
{
|
||||
switch (_choice)
|
||||
{
|
||||
case CrossoverChoice::SinglePoint:
|
||||
return randomPointCrossover();
|
||||
case CrossoverChoice::TwoPoint:
|
||||
return randomTwoPointCrossover();
|
||||
case CrossoverChoice::Uniform:
|
||||
assert(_uniformCrossoverSwapChance.has_value());
|
||||
return uniformCrossover(_uniformCrossoverSwapChance.value());
|
||||
default:
|
||||
assertThrow(false, solidity::util::Exception, "Invalid CrossoverChoice value.");
|
||||
};
|
||||
}
|
||||
|
||||
function<SymmetricCrossover> phaser::buildSymmetricCrossoverOperator(
|
||||
CrossoverChoice _choice,
|
||||
optional<double> _uniformCrossoverSwapChance
|
||||
)
|
||||
{
|
||||
switch (_choice)
|
||||
{
|
||||
case CrossoverChoice::SinglePoint:
|
||||
return symmetricRandomPointCrossover();
|
||||
case CrossoverChoice::TwoPoint:
|
||||
return symmetricRandomTwoPointCrossover();
|
||||
case CrossoverChoice::Uniform:
|
||||
assert(_uniformCrossoverSwapChance.has_value());
|
||||
return symmetricUniformCrossover(_uniformCrossoverSwapChance.value());
|
||||
default:
|
||||
assertThrow(false, solidity::util::Exception, "Invalid CrossoverChoice value.");
|
||||
};
|
||||
}
|
||||
|
||||
Population RandomAlgorithm::runNextRound(Population _population)
|
||||
{
|
||||
RangeSelection elite(0.0, m_options.elitePoolSize);
|
||||
|
@ -20,11 +20,31 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tools/yulPhaser/Mutations.h>
|
||||
#include <tools/yulPhaser/Population.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace solidity::phaser
|
||||
{
|
||||
|
||||
enum class CrossoverChoice
|
||||
{
|
||||
SinglePoint,
|
||||
TwoPoint,
|
||||
Uniform,
|
||||
};
|
||||
|
||||
std::function<Crossover> buildCrossoverOperator(
|
||||
CrossoverChoice _choice,
|
||||
std::optional<double> _uniformCrossoverSwapChance
|
||||
);
|
||||
|
||||
std::function<SymmetricCrossover> buildSymmetricCrossoverOperator(
|
||||
CrossoverChoice _choice,
|
||||
std::optional<double> _uniformCrossoverSwapChance
|
||||
);
|
||||
|
||||
/**
|
||||
* Abstract base class for genetic algorithms.
|
||||
* The main feature is the @a runNextRound() method that executes one round of the algorithm,
|
||||
|
Loading…
Reference in New Issue
Block a user