From 96a1177a67fd2fdcb05ba356f3c298be64b8efda Mon Sep 17 00:00:00 2001 From: RyleyGG Date: Mon, 12 Oct 2020 16:11:41 -0400 Subject: [PATCH] Updated commenting and removed old survivor selection method Updated commenting and removed old survivor selection method --- .../survivor_selection_methods.py | 33 ++++--------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/src/survivor_selection/survivor_selection_methods.py b/src/survivor_selection/survivor_selection_methods.py index d872862..530ffd8 100644 --- a/src/survivor_selection/survivor_selection_methods.py +++ b/src/survivor_selection/survivor_selection_methods.py @@ -7,36 +7,15 @@ from initialization.chromosome_structure.chromosome import Chromosome class Survivor_Selection: """Survivor selection determines which individuals should be brought to the next generation""" - """ Pretty sure this isn't actually survivor selection - seems like its 'cheating' - def repeated_crossover(ga, next_population): - while len(next_population.get_all_chromosomes()) < ga.population_size: - crossover_pool = ga.population.mating_pool - - split_point = random.randint(0,ga.chromosome_length) - chromosome_list = [] - for i in range(len(crossover_pool)): - if i + 1 < len(crossover_pool): - new_gene_set = [] - parent_one = crossover_pool[i].get_genes() - parent_two = crossover_pool[i+1].get_genes() - new_gene_set.extend(parent_one[0:split_point]) - new_gene_set.extend(parent_two[split_point:]) - new_chromosome = create_chromosome(new_gene_set) - chromosome_list.append(new_chromosome) - - - for i in range(len(chromosome_list)): - next_population.add_chromosome(chromosome_list[i]) - if len(next_population.get_all_chromosomes()) >= ga.population_size: - break - return 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""" 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