Compare commits

..

1 Commits

Author SHA1 Message Date
coolneng 046b1a043a
Implement uniform generational genetic algorithm 2021-06-20 05:24:56 +02:00
1 changed files with 6 additions and 5 deletions

View File

@ -201,11 +201,12 @@ def generational_replacement(prev_population, current_population):
def get_best_elements(population): def get_best_elements(population):
first_element = max(population, key=lambda x: x.fitness.values[0]) select_population = deepcopy(population)
first_index = get_individual_index(first_element, population) first_element = max(select_population, key=lambda x: x.fitness.values[0])
population.pop(first_index) first_index = get_individual_index(first_element, select_population)
second_element = max(population, key=lambda x: x.fitness.values[0]) select_population.pop(first_index)
second_index = get_individual_index(second_element, population) second_element = max(select_population, key=lambda x: x.fitness.values[0])
second_index = get_individual_index(second_element, select_population)
return first_index, second_index return first_index, second_index