Some cleaning up

Added Population.size() and cleaned up the survivor selection.
This commit is contained in:
SimpleArt
2020-10-12 16:53:06 -04:00
parent 159506824a
commit 8137bb64d9
3 changed files with 7 additions and 14 deletions

View File

@ -8,6 +8,10 @@ class Population:
self.fitness = None
self.mating_pool = []
def size(self):
"""Returns the size of the population"""
return len(self.chromosome_list)
def get_closet_fitness(self,value):
"""Get the chomosome that has the closets fitness to the value defined"""
pass

View File

@ -44,5 +44,3 @@ class Mutation_Methods:
gene_mutate_count = int(gene_mutate_count_static)
return chromosome_set

View File

@ -7,15 +7,6 @@ from initialization.chromosome_structure.chromosome import Chromosome
class Survivor_Selection:
"""Survivor selection determines which individuals should be brought to the next generation"""
def remove_worst(ga, next_population):
"""
Will bring all but the worst-performing chromosomes from the current generation.
The exact number of chromosomes removed depends on how many offspring were generated by parent selection.
"""
iterator = 0
# While the size of the next population is less than it should be (as determined by the user)
while len(next_population.get_all_chromosomes()) < ga.population_size:
# Add the best chromosome from the current population that hasn't already been brought over
next_population.add_chromosome(ga.population.get_all_chromosomes()[iterator])
iterator += 1
return next_population
def fill_in_best(ga, next_population):
"""Fills in the next population with the best chromosomes from the last population until the population size is met."""
return ga.population[:ga.population_size-next_population.size()] + next_population