mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] Change the design of crossover operators so that they produce a single chromosome rather than a pair
This commit is contained in:
@@ -71,7 +71,7 @@ void GenerationalElitistWithExclusivePools::runNextRound()
|
||||
)
|
||||
) +
|
||||
m_population.select(elite).crossover(
|
||||
RandomPairSelection(m_options.crossoverPoolSize / elitePoolSize / 2),
|
||||
RandomPairSelection(m_options.crossoverPoolSize / elitePoolSize),
|
||||
randomPointCrossover()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ function<Mutation> phaser::alternativeMutations(
|
||||
namespace
|
||||
{
|
||||
|
||||
ChromosomePair buildChromosomesBySwappingParts(
|
||||
Chromosome buildChromosomesBySwappingParts(
|
||||
Chromosome const& _chromosome1,
|
||||
Chromosome const& _chromosome2,
|
||||
size_t _crossoverPoint
|
||||
@@ -110,15 +110,9 @@ ChromosomePair buildChromosomesBySwappingParts(
|
||||
auto begin1 = _chromosome1.optimisationSteps().begin();
|
||||
auto begin2 = _chromosome2.optimisationSteps().begin();
|
||||
|
||||
return ChromosomePair(
|
||||
Chromosome(
|
||||
vector<string>(begin1, begin1 + _crossoverPoint) +
|
||||
vector<string>(begin2 + _crossoverPoint, _chromosome2.optimisationSteps().end())
|
||||
),
|
||||
Chromosome(
|
||||
vector<string>(begin2, begin2 + _crossoverPoint) +
|
||||
vector<string>(begin1 + _crossoverPoint, _chromosome1.optimisationSteps().end())
|
||||
)
|
||||
return Chromosome(
|
||||
vector<string>(begin1, begin1 + _crossoverPoint) +
|
||||
vector<string>(begin2 + _crossoverPoint, _chromosome2.optimisationSteps().end())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,10 +28,8 @@
|
||||
namespace solidity::phaser
|
||||
{
|
||||
|
||||
using ChromosomePair = std::tuple<Chromosome, Chromosome>;
|
||||
|
||||
using Mutation = Chromosome(Chromosome const&);
|
||||
using Crossover = ChromosomePair(Chromosome const&, Chromosome const&);
|
||||
using Crossover = Chromosome(Chromosome const&, Chromosome const&);
|
||||
|
||||
// MUTATIONS
|
||||
|
||||
@@ -64,10 +62,9 @@ std::function<Mutation> alternativeMutations(
|
||||
std::function<Crossover> randomPointCrossover();
|
||||
|
||||
/// Creates a crossover operator that always chooses a point that lies at @a _crossoverPoint
|
||||
/// percent of the length of the shorter chromosome. Then creates a pair of chromosomes by
|
||||
/// splitting both inputs at the crossover point and stitching the resulting parts. The first
|
||||
/// output is created from the first half or first input and the second half of the second input
|
||||
/// The second output from the remaining two halves.
|
||||
/// percent of the length of the shorter chromosome. Then creates a new chromosome by
|
||||
/// splitting both inputs at the crossover point and stitching output from the first half or first
|
||||
/// input and the second half of the second input.
|
||||
///
|
||||
/// Avoids selecting position 0 (since this just produces a chromosome identical to the second one)
|
||||
/// unless there is no other choice (i.e. one of the chromosomes is empty).
|
||||
|
||||
@@ -108,12 +108,11 @@ Population Population::crossover(PairSelection const& _selection, function<Cross
|
||||
vector<Individual> crossedIndividuals;
|
||||
for (auto const& [i, j]: _selection.materialise(m_individuals.size()))
|
||||
{
|
||||
auto [childChromosome1, childChromosome2] = _crossover(
|
||||
auto childChromosome = _crossover(
|
||||
m_individuals[i].chromosome,
|
||||
m_individuals[j].chromosome
|
||||
);
|
||||
crossedIndividuals.emplace_back(move(childChromosome1), *m_fitnessMetric);
|
||||
crossedIndividuals.emplace_back(move(childChromosome2), *m_fitnessMetric);
|
||||
crossedIndividuals.emplace_back(move(childChromosome), *m_fitnessMetric);
|
||||
}
|
||||
|
||||
return Population(m_fitnessMetric, crossedIndividuals);
|
||||
|
||||
Reference in New Issue
Block a user