[yul-phaser] GenerationalElitistWithExclusivePools: Refactor runNextRound() for less nesting and more readability

This commit is contained in:
Kamil Śliwak 2020-03-11 02:29:20 +01:00
parent 8c86a4983d
commit 879f6e17e9

View File

@ -43,13 +43,12 @@ Population RandomAlgorithm::runNextRound(Population _population)
Population GenerationalElitistWithExclusivePools::runNextRound(Population _population) Population GenerationalElitistWithExclusivePools::runNextRound(Population _population)
{ {
double elitePoolSize = 1.0 - (m_options.mutationPoolSize + m_options.crossoverPoolSize); double elitePoolSize = 1.0 - (m_options.mutationPoolSize + m_options.crossoverPoolSize);
RangeSelection elite(0.0, elitePoolSize);
return RangeSelection elitePool(0.0, elitePoolSize);
_population.select(elite) + RandomSelection mutationPoolFromElite(m_options.mutationPoolSize / elitePoolSize);
_population.select(elite).mutate( RandomPairSelection crossoverPoolFromElite(m_options.crossoverPoolSize / elitePoolSize);
RandomSelection(m_options.mutationPoolSize / elitePoolSize),
alternativeMutations( std::function<Mutation> mutationOperator = alternativeMutations(
m_options.randomisationChance, m_options.randomisationChance,
geneRandomisation(m_options.percentGenesToRandomise), geneRandomisation(m_options.percentGenesToRandomise),
alternativeMutations( alternativeMutations(
@ -57,10 +56,11 @@ Population GenerationalElitistWithExclusivePools::runNextRound(Population _popul
geneDeletion(m_options.percentGenesToAddOrDelete), geneDeletion(m_options.percentGenesToAddOrDelete),
geneAddition(m_options.percentGenesToAddOrDelete) geneAddition(m_options.percentGenesToAddOrDelete)
) )
)
) +
_population.select(elite).crossover(
RandomPairSelection(m_options.crossoverPoolSize / elitePoolSize),
randomPointCrossover()
); );
std::function<Crossover> crossoverOperator = randomPointCrossover();
return
_population.select(elitePool) +
_population.select(elitePool).mutate(mutationPoolFromElite, mutationOperator) +
_population.select(elitePool).crossover(crossoverPoolFromElite, crossoverOperator);
} }