From 1348a3c65575415ea1d9ddf949ef786928a7df04 Mon Sep 17 00:00:00 2001 From: Jakob Jordan Date: Wed, 1 Jul 2020 22:33:14 +0200 Subject: [PATCH] Simplify create_new_parent_population in mu_plus_lambda --- cgp/ea/mu_plus_lambda.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/cgp/ea/mu_plus_lambda.py b/cgp/ea/mu_plus_lambda.py index d3623bd3..9d5e2458 100644 --- a/cgp/ea/mu_plus_lambda.py +++ b/cgp/ea/mu_plus_lambda.py @@ -182,19 +182,8 @@ def sort_func(zipped_ind: Tuple[int, IndividualBase]) -> float: def _create_new_parent_population( self, n_parents: int, combined: List[IndividualBase] ) -> List[IndividualBase]: - # create new parent population by picking the `n_parents` individuals - # with the highest fitness - parents: List[IndividualBase] = [] - for i in range(n_parents): - # note: unclear whether clone() is needed here; using - # clone() avoids accidentally sharing references across - # individuals, but might incur a performance penalty - new_individual = combined[i].clone() - - # since this individual is genetically identical to its - # parent, the identifier is the same - new_individual.idx = combined[i].idx - - parents.append(new_individual) - - return parents + """Create the new parent population by picking the first `n_parents` + individuals from the combined population. + + """ + return combined[:n_parents]