Skip to content
Snippets Groups Projects
Commit 5f8779f1 authored by Sepehr Madani's avatar Sepehr Madani
Browse files

Remove duplicate chromosomes by genes' hash-values

parent af27dd8e
No related branches found
No related tags found
No related merge requests found
......@@ -154,6 +154,15 @@ class GeneticAlgorithm(BaseAlgorithm):
)
chromosome.needs_update = False
# Remove redundant chromosomes
hash_list = []
for chromosome in self.chromosomes:
this_hash = hash(chromosome)
if this_hash in hash_list:
chromosome = Chromosome()
else:
hash_list.append(this_hash)
# Sort sample by chromosome score
self.chromosomes.sort(key=lambda x: x.get_score(), reverse=True)
......@@ -175,7 +184,6 @@ class GeneticAlgorithm(BaseAlgorithm):
for idx, original in enumerate(self.chromosomes[1:self.sample_size + 1]):
mutated = self.chromosomes[idx + self.sample_size - 1]
mutated.gene = original.gene.copy()
mutated.needs_update = True
mutated.mutate()
def make_weights(self, chromosome):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment