Added hashing methods for sets/dictionaries.
This commit is contained in:
@ -112,6 +112,11 @@ class Chromosome():
|
||||
return self.gene_list == chromosome.gene_list
|
||||
|
||||
|
||||
def __hash__(self):
|
||||
"""Hash chromosomes by genes so they can be used in sets/dictionaries."""
|
||||
return hash(tuple(self))
|
||||
|
||||
|
||||
def __add__(self, chromosome):
|
||||
"""Return self + chromosome, a chromosome made by concatenating the genes."""
|
||||
return Chromosome(chain(self, chromosome))
|
||||
|
||||
@ -19,6 +19,11 @@ class Gene:
|
||||
return self.value == Gene(other_gene).value
|
||||
|
||||
|
||||
def __hash__(self):
|
||||
"""Hash genes by value so that they can be used in sets/dictionaries."""
|
||||
return hash(self.value)
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
"""
|
||||
Allows the user to use
|
||||
|
||||
Reference in New Issue
Block a user