def next_generation(self, generation: List[dict], scores: List[float], iteration: int) -> List[dict]:
next_population = self.selection_of_best_with_weights(generation, scores)<EOL>log.info("<STR_LIT>".format(self.n_saved_best_pretrained))<EOL>offsprings = self.crossover(generation, scores)<EOL>changable_next = self.mutation(offsprings)<EOL>next_population.extend(changable_next)<EOL>for i in range(self.n_saved_best_pretrained):<EOL><INDENT>if self.train_partition != <NUM_LIT:1>:<EOL><INDENT>file_ext = str(Path(next_population[i]["<STR_LIT>"]["<STR_LIT:train>"]).suffix)<EOL>next_population[i]["<STR_LIT>"]["<STR_LIT:train>"] = "<STR_LIT:_>".join(<EOL>Path(next_population[i]["<STR_LIT>"]["<STR_LIT:train>"]).stem.split("<STR_LIT:_>")[:-<NUM_LIT:1>]<EOL>) + "<STR_LIT:_>" + str(iteration % self.train_partition) + file_ext<EOL><DEDENT>if self.elitism_with_weights:<EOL><INDENT>self.insert_value_or_dict_into_config(<EOL>next_population[i], self.path_to_models_load_path,<EOL>self.get_value_from_config(next_population[i], self.path_to_models_save_path))<EOL><DEDENT>else:<EOL><INDENT>self.insert_value_or_dict_into_config(<EOL>next_population[i], self.path_to_models_load_path,<EOL>str(self.models_path / f"<STR_LIT>" / f"<STR_LIT>"))<EOL><DEDENT>self.insert_value_or_dict_into_config(<EOL>next_population[i], self.path_to_models_save_path,<EOL>str(self.models_path / f"<STR_LIT>" / f"<STR_LIT>"))<EOL><DEDENT>for i in range(self.n_saved_best_pretrained, self.population_size):<EOL><INDENT>if self.train_partition != <NUM_LIT:1>:<EOL><INDENT>file_ext = str(Path(next_population[i]["<STR_LIT>"]["<STR_LIT:train>"]).suffix)<EOL>next_population[i]["<STR_LIT>"]["<STR_LIT:train>"] = "<STR_LIT:_>".join(<EOL>[str(p) for p in Path(next_population[i]["<STR_LIT>"]["<STR_LIT:train>"]).stem.split("<STR_LIT:_>")[:-<NUM_LIT:1>]])+ "<STR_LIT:_>" + str(iteration % self.train_partition) + file_ext<EOL><DEDENT>self.insert_value_or_dict_into_config(<EOL>next_population[i], self.path_to_models_save_path,<EOL>str(self.models_path / f"<STR_LIT>" / f"<STR_LIT>"))<EOL>self.insert_value_or_dict_into_config(<EOL>next_population[i], self.path_to_models_load_path,<EOL>str(self.models_path / f"<STR_LIT>" / f"<STR_LIT>"))<EOL>next_population[i]["<STR_LIT>"] = self.evolution_model_id<EOL>self.evolution_model_id += <NUM_LIT:1><EOL><DEDENT>return next_population<EOL>
Provide replacement

Args:
    generation: current generation (set of self.population_size configs
    scores: corresponding scores that should be maximized
    iteration: iteration number

Returns:
    the next generation according to the given scores of current generation