Merge pull request #18 from danielwilczak101/development

Added hashing methods for sets/dictionaries.
This commit is contained in:
Daniel Wilczak
2021-05-04 01:39:44 -04:00
committed by GitHub
2 changed files with 10 additions and 0 deletions

View File

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

View File

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