Fixed scope of function decorators

This commit is contained in:
SimpleArt
2020-11-19 22:28:04 -05:00
parent 46b4dc749d
commit 3d10adb2d9
4 changed files with 85 additions and 81 deletions

View File

@ -1,13 +1,13 @@
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))
@__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 +15,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 +23,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"""