[yul-phaser] Add GenerationalElitistWithExclusivePools algorithm

This commit is contained in:
Kamil Śliwak
2020-03-09 13:21:48 +01:00
parent 7e80ac861f
commit fc4fedb214
3 changed files with 182 additions and 0 deletions
+27
View File
@@ -16,7 +16,9 @@
*/
#include <tools/yulPhaser/GeneticAlgorithms.h>
#include <tools/yulPhaser/Mutations.h>
#include <tools/yulPhaser/Selections.h>
#include <tools/yulPhaser/PairSelections.h>
using namespace std;
using namespace solidity::phaser;
@@ -48,3 +50,28 @@ void RandomAlgorithm::runNextRound()
m_options.maxChromosomeLength
);
}
void GenerationalElitistWithExclusivePools::runNextRound()
{
double elitePoolSize = 1.0 - (m_options.mutationPoolSize + m_options.crossoverPoolSize);
RangeSelection elite(0.0, elitePoolSize);
m_population =
m_population.select(elite) +
m_population.select(elite).mutate(
RandomSelection(m_options.mutationPoolSize / elitePoolSize),
alternativeMutations(
m_options.randomisationChance,
geneRandomisation(m_options.percentGenesToRandomise),
alternativeMutations(
m_options.deletionVsAdditionChance,
geneDeletion(m_options.percentGenesToAddOrDelete),
geneAddition(m_options.percentGenesToAddOrDelete)
)
)
) +
m_population.select(elite).crossover(
RandomPairSelection(m_options.crossoverPoolSize / elitePoolSize / 2),
randomPointCrossover()
);
}