diff --git a/src/survivor_selection/survivor_selection_methods.py b/src/survivor_selection/survivor_selection_methods.py index 48d9128..fc5def3 100644 --- a/src/survivor_selection/survivor_selection_methods.py +++ b/src/survivor_selection/survivor_selection_methods.py @@ -1,13 +1,17 @@ import random +def append_to_next_population(survivor_method): + return lambda ga: ga.population.append_children(survivor_method(ga)) + + class Survivor_Selection: """Survivor selection determines which individuals should be brought to the next generation""" def __append_to_next_population(survivor_method): - return lambda ga: ga.population.append_children(survivor_method(ga)) + return append_to_next_population(survivor_method) - @__append_to_next_population + @append_to_next_population def fill_in_best(ga): """Fills in the next population with the best chromosomes from the last population""" @@ -15,7 +19,7 @@ class Survivor_Selection: return ga.population[:needed_amount] - @__append_to_next_population + @append_to_next_population def fill_in_random(ga): """Fills in the next population with random chromosomes from the last population""" @@ -23,7 +27,7 @@ class Survivor_Selection: return [random.choice(ga.population) for n in range(needed_amount)] - @__append_to_next_population + @append_to_next_population def fill_in_parents_then_random(ga): """Fills in the next population with all parents followed by random chromosomes from the last population"""