Compare commits

..

1 Commits

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

View File

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