mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] Chromosome: Add stepsToGenes() and genesToSteps()
This commit is contained in:
@@ -37,12 +37,6 @@ ostream& operator<<(ostream& _stream, Chromosome const& _chromosome);
|
||||
|
||||
}
|
||||
|
||||
Chromosome::Chromosome(string const& _optimisationSteps)
|
||||
{
|
||||
for (char abbreviation: _optimisationSteps)
|
||||
m_optimisationSteps.push_back(OptimiserSuite::stepAbbreviationToNameMap().at(abbreviation));
|
||||
}
|
||||
|
||||
Chromosome Chromosome::makeRandom(size_t _length)
|
||||
{
|
||||
vector<string> steps;
|
||||
@@ -54,10 +48,7 @@ Chromosome Chromosome::makeRandom(size_t _length)
|
||||
|
||||
ostream& phaser::operator<<(ostream& _stream, Chromosome const& _chromosome)
|
||||
{
|
||||
for (auto const& stepName: _chromosome.m_optimisationSteps)
|
||||
_stream << OptimiserSuite::stepNameToAbbreviationMap().at(stepName);
|
||||
|
||||
return _stream;
|
||||
return _stream << Chromosome::stepsToGenes(_chromosome.m_optimisationSteps);
|
||||
}
|
||||
|
||||
vector<string> Chromosome::allStepNames()
|
||||
@@ -75,3 +66,21 @@ string const& Chromosome::randomOptimisationStep()
|
||||
|
||||
return stepNames[SimulationRNG::uniformInt(0, stepNames.size() - 1)];
|
||||
}
|
||||
|
||||
string Chromosome::stepsToGenes(vector<string> const& _optimisationSteps)
|
||||
{
|
||||
string genes;
|
||||
for (string const& stepName: _optimisationSteps)
|
||||
genes.push_back(OptimiserSuite::stepNameToAbbreviationMap().at(stepName));
|
||||
|
||||
return genes;
|
||||
}
|
||||
|
||||
vector<string> Chromosome::genesToSteps(string const& _genes)
|
||||
{
|
||||
vector<string> steps;
|
||||
for (char abbreviation: _genes)
|
||||
steps.push_back(OptimiserSuite::stepAbbreviationToNameMap().at(abbreviation));
|
||||
|
||||
return steps;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ public:
|
||||
Chromosome() = default;
|
||||
explicit Chromosome(std::vector<std::string> _optimisationSteps):
|
||||
m_optimisationSteps(std::move(_optimisationSteps)) {}
|
||||
explicit Chromosome(std::string const& _optimisationSteps);
|
||||
explicit Chromosome(std::string const& _genes):
|
||||
m_optimisationSteps(genesToSteps(_genes)) {}
|
||||
static Chromosome makeRandom(size_t _length);
|
||||
|
||||
size_t length() const { return m_optimisationSteps.size(); }
|
||||
@@ -55,6 +56,8 @@ public:
|
||||
bool operator!=(Chromosome const& _other) const { return !(*this == _other); }
|
||||
|
||||
static std::string const& randomOptimisationStep();
|
||||
static std::string stepsToGenes(std::vector<std::string> const& _optimisationSteps);
|
||||
static std::vector<std::string> genesToSteps(std::string const& _genes);
|
||||
|
||||
private:
|
||||
static std::vector<std::string> allStepNames();
|
||||
|
||||
Reference in New Issue
Block a user