Consistent function decorator format
This commit is contained in:
@ -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"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user