mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] Population: Extract conversion from chromosomes to individuals into a separate function
This commit is contained in:
parent
930a9918a6
commit
41f36f421d
@ -63,13 +63,6 @@ bool phaser::isFitter(Individual const& a, Individual const& b)
|
||||
);
|
||||
}
|
||||
|
||||
Population::Population(Program _program, vector<Chromosome> const& _chromosomes):
|
||||
m_program{move(_program)}
|
||||
{
|
||||
for (auto const& chromosome: _chromosomes)
|
||||
m_individuals.push_back({chromosome});
|
||||
}
|
||||
|
||||
Population Population::makeRandom(
|
||||
Program _program,
|
||||
size_t _size,
|
||||
@ -175,3 +168,14 @@ void Population::randomizeWorstChromosomes(
|
||||
*individual = {Chromosome::makeRandom(binomialChromosomeLength(MaxChromosomeLength))};
|
||||
}
|
||||
}
|
||||
|
||||
vector<Individual> Population::chromosomesToIndividuals(
|
||||
vector<Chromosome> _chromosomes
|
||||
)
|
||||
{
|
||||
vector<Individual> individuals;
|
||||
for (auto& chromosome: _chromosomes)
|
||||
individuals.push_back({move(chromosome)});
|
||||
|
||||
return individuals;
|
||||
}
|
||||
|
@ -73,7 +73,11 @@ class Population
|
||||
public:
|
||||
static constexpr size_t MaxChromosomeLength = 30;
|
||||
|
||||
explicit Population(Program _program, std::vector<Chromosome> const& _chromosomes = {});
|
||||
explicit Population(Program _program, std::vector<Chromosome> _chromosomes = {}):
|
||||
Population(
|
||||
std::move(_program),
|
||||
chromosomesToIndividuals(std::move(_chromosomes))
|
||||
) {}
|
||||
|
||||
static Population makeRandom(
|
||||
Program _program,
|
||||
@ -114,6 +118,9 @@ private:
|
||||
std::vector<Individual>& _individuals,
|
||||
size_t _count
|
||||
);
|
||||
static std::vector<Individual> chromosomesToIndividuals(
|
||||
std::vector<Chromosome> _chromosomes
|
||||
);
|
||||
|
||||
Program m_program;
|
||||
std::vector<Individual> m_individuals;
|
||||
|
Loading…
Reference in New Issue
Block a user