diff --git a/src/initialization/population_structure/population.py b/src/initialization/population_structure/population.py index 98f5518..435af04 100644 --- a/src/initialization/population_structure/population.py +++ b/src/initialization/population_structure/population.py @@ -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 diff --git a/src/mutation/mutation_methods.py b/src/mutation/mutation_methods.py index 7515b4d..e1e3166 100644 --- a/src/mutation/mutation_methods.py +++ b/src/mutation/mutation_methods.py @@ -44,5 +44,3 @@ class Mutation_Methods: gene_mutate_count = int(gene_mutate_count_static) return chromosome_set - - diff --git a/src/survivor_selection/survivor_selection_methods.py b/src/survivor_selection/survivor_selection_methods.py index 530ffd8..99e8daa 100644 --- a/src/survivor_selection/survivor_selection_methods.py +++ b/src/survivor_selection/survivor_selection_methods.py @@ -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 \ No newline at end of file + 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