From 1a8219d720543c1aad8b303aac906534fa611e92 Mon Sep 17 00:00:00 2001 From: SimpleArt <71458112+SimpleArt@users.noreply.github.com> Date: Sat, 21 Nov 2020 16:39:43 -0500 Subject: [PATCH] Simplified using random.choices --- src/survivor_selection/survivor_selection_methods.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/survivor_selection/survivor_selection_methods.py b/src/survivor_selection/survivor_selection_methods.py index d6b4d78..4848c98 100644 --- a/src/survivor_selection/survivor_selection_methods.py +++ b/src/survivor_selection/survivor_selection_methods.py @@ -26,7 +26,7 @@ class Survivor_Selection: """Fills in the next population with random chromosomes from the last population""" needed_amount = len(ga.population) - ga.population.total_children - return [random.choice(ga.population) for n in range(needed_amount)] + return random.choices(ga.population, k=needed_amount) @append_to_next_population @@ -37,4 +37,4 @@ class Survivor_Selection: parent_amount = min(ga.population.total_parents, needed_amount) random_amount = needed_amount - parent_amount - return ga.population.get_mating_pool()[:parent_amount] + [random.choice(ga.population) for n in range(random_amount)] + return ga.population.get_mating_pool()[:parent_amount] + random.choices(ga.population, k=random_amount)