Skip to content

Commit

Permalink
Simplify create_new_parent_population in mu_plus_lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobj committed Jul 3, 2020
1 parent 3f6639e commit 1348a3c
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions cgp/ea/mu_plus_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit 1348a3c

Please sign in to comment.