Updated commenting and removed old survivor selection method
Updated commenting and removed old survivor selection method
This commit is contained in:
@ -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
|
||||
Reference in New Issue
Block a user