mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	[yul-phaser] Population: Equality operators for populations and individuals
This commit is contained in:
		
							parent
							
								
									d9c5e2dc9f
								
							
						
					
					
						commit
						31d8d5930a
					
				| @ -125,6 +125,13 @@ Population operator+(Population _a, Population _b) | |||||||
| 	return Population(_a.m_program, move(_a.m_individuals) + move(_b.m_individuals)); | 	return Population(_a.m_program, move(_a.m_individuals) + move(_b.m_individuals)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | bool Population::operator==(Population const& _other) const | ||||||
|  | { | ||||||
|  | 	// TODO: Comparing programs is pretty heavy but it's just a stopgap. It will soon be replaced
 | ||||||
|  | 	// by a comparison of fitness metric associated with the population (once metrics are introduced).
 | ||||||
|  | 	return m_individuals == _other.m_individuals && toString(m_program) == toString(_other.m_program); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| ostream& phaser::operator<<(ostream& _stream, Population const& _population) | ostream& phaser::operator<<(ostream& _stream, Population const& _population) | ||||||
| { | { | ||||||
| 	auto individual = _population.m_individuals.begin(); | 	auto individual = _population.m_individuals.begin(); | ||||||
|  | |||||||
| @ -48,6 +48,9 @@ struct Individual | |||||||
| 	Chromosome chromosome; | 	Chromosome chromosome; | ||||||
| 	std::optional<size_t> fitness = std::nullopt; | 	std::optional<size_t> fitness = std::nullopt; | ||||||
| 
 | 
 | ||||||
|  | 	bool operator==(Individual const& _other) const { return fitness == _other.fitness && chromosome == _other.chromosome; } | ||||||
|  | 	bool operator!=(Individual const& _other) const { return !(*this == _other); } | ||||||
|  | 
 | ||||||
| 	friend std::ostream& operator<<(std::ostream& _stream, Individual const& _individual); | 	friend std::ostream& operator<<(std::ostream& _stream, Individual const& _individual); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| @ -93,6 +96,9 @@ public: | |||||||
| 	static size_t binomialChromosomeLength(size_t _max) { return SimulationRNG::binomialInt(_max, 0.5); } | 	static size_t binomialChromosomeLength(size_t _max) { return SimulationRNG::binomialInt(_max, 0.5); } | ||||||
| 	static size_t measureFitness(Chromosome const& _chromosome, Program const& _program); | 	static size_t measureFitness(Chromosome const& _chromosome, Program const& _program); | ||||||
| 
 | 
 | ||||||
|  | 	bool operator==(Population const& _other) const; | ||||||
|  | 	bool operator!=(Population const& _other) const { return !(*this == _other); } | ||||||
|  | 
 | ||||||
| 	friend std::ostream& operator<<(std::ostream& _stream, Population const& _population); | 	friend std::ostream& operator<<(std::ostream& _stream, Population const& _population); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user