mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] Add RandomAlgorithm
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
|
||||
#include <tools/yulPhaser/GeneticAlgorithms.h>
|
||||
#include <tools/yulPhaser/Selections.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity::phaser;
|
||||
@@ -30,3 +31,20 @@ void GeneticAlgorithm::run(optional<size_t> _numRounds)
|
||||
m_outputStream << m_population;
|
||||
}
|
||||
}
|
||||
|
||||
void RandomAlgorithm::runNextRound()
|
||||
{
|
||||
RangeSelection elite(0.0, m_options.elitePoolSize);
|
||||
|
||||
Population elitePopulation = m_population.select(elite);
|
||||
size_t replacementCount = m_population.individuals().size() - elitePopulation.individuals().size();
|
||||
|
||||
m_population =
|
||||
move(elitePopulation) +
|
||||
Population::makeRandom(
|
||||
m_population.fitnessMetric(),
|
||||
replacementCount,
|
||||
m_options.minChromosomeLength,
|
||||
m_options.maxChromosomeLength
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user