Implemented __hash__
This commit is contained in:
@ -107,6 +107,17 @@ class Chromosome():
|
|||||||
return (to_gene(gene) in self.gene_list)
|
return (to_gene(gene) in self.gene_list)
|
||||||
|
|
||||||
|
|
||||||
|
def __hash__(self):
|
||||||
|
"""
|
||||||
|
Returns hash(self).
|
||||||
|
Allows the user to use
|
||||||
|
{chromosome}
|
||||||
|
{chromosome: x}
|
||||||
|
or any other thing requiring hashes with chromosomes.
|
||||||
|
"""
|
||||||
|
return hash(tuple(self))
|
||||||
|
|
||||||
|
|
||||||
def __eq__(self, chromosome):
|
def __eq__(self, chromosome):
|
||||||
"""Returns self == chromosome, True if all genes match."""
|
"""Returns self == chromosome, True if all genes match."""
|
||||||
return self.gene_list == chromosome.gene_list
|
return self.gene_list == chromosome.gene_list
|
||||||
|
|||||||
@ -159,6 +159,17 @@ class Population:
|
|||||||
return (to_chromosome(chromosome) in self.chromosome_list)
|
return (to_chromosome(chromosome) in self.chromosome_list)
|
||||||
|
|
||||||
|
|
||||||
|
def __hash__(self):
|
||||||
|
"""
|
||||||
|
Returns hash(self).
|
||||||
|
Allows the user to use
|
||||||
|
{population}
|
||||||
|
{population: x}
|
||||||
|
or any other thing requiring hashes with populations.
|
||||||
|
"""
|
||||||
|
return hash(tuple(self))
|
||||||
|
|
||||||
|
|
||||||
def __eq__(self, population):
|
def __eq__(self, population):
|
||||||
"""Returns self == population, True if all chromosomes match."""
|
"""Returns self == population, True if all chromosomes match."""
|
||||||
return self.chromosome_list == population.chromosome_list
|
return self.chromosome_list == population.chromosome_list
|
||||||
|
|||||||
Reference in New Issue
Block a user