[yul-phaser] Population: Extract conversion from chromosomes to individuals into a separate function

This commit is contained in:
cameel 2020-02-05 15:15:17 +01:00 committed by Kamil Śliwak
parent 930a9918a6
commit 41f36f421d
2 changed files with 19 additions and 8 deletions

View File

@ -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;
}

View File

@ -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;