Added ga.adapt()

This commit is contained in:
SimpleArt
2020-11-27 19:12:40 -05:00
parent a87103b80c
commit 1197447d7e
3 changed files with 81 additions and 9 deletions

View File

@ -46,13 +46,16 @@ class Population:
def append_children(self, chromosome_list):
"""Appends a list of chromosomes to the next population"""
self.next_population += chromosome_list
"""Appends a list of chromosomes to the next population.
Appends to the front so that chromosomes with fitness
values already will stay sorted.
"""
self.next_population = chromosome_list + self.next_population
def sort_by_best_fitness(self, ga):
"""Sorts the population by fitness"""
self.chromosome_list = ga.sort_by_best_fitness(self.chromosome_list)
ga.sort_by_best_fitness(self.chromosome_list, in_place = True)
def add_chromosome(self, chromosome, index = None):