Skip to content

Commit

Permalink
Merge pull request #170 from jakobj/maint/refactor-create-new-parent-pop
Browse files Browse the repository at this point in the history
Simplify `create_new_parent_population` in `mu_plus_lambda`
  • Loading branch information
mschmidt87 committed Jul 4, 2020
2 parents 69dd1ca + 1348a3c commit 2fce8bd
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 @@ -189,19 +189,8 @@ def sort_func(ind: 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 2fce8bd

Please sign in to comment.