Consistent function decorator format
This commit is contained in:
@ -1,13 +1,17 @@
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
|
def append_to_next_population(survivor_method):
|
||||||
|
return lambda ga: ga.population.append_children(survivor_method(ga))
|
||||||
|
|
||||||
|
|
||||||
class Survivor_Selection:
|
class Survivor_Selection:
|
||||||
"""Survivor selection determines which individuals should be brought to the next generation"""
|
"""Survivor selection determines which individuals should be brought to the next generation"""
|
||||||
|
|
||||||
def __append_to_next_population(survivor_method):
|
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):
|
def fill_in_best(ga):
|
||||||
"""Fills in the next population with the best chromosomes from the last population"""
|
"""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]
|
return ga.population[:needed_amount]
|
||||||
|
|
||||||
|
|
||||||
@__append_to_next_population
|
@append_to_next_population
|
||||||
def fill_in_random(ga):
|
def fill_in_random(ga):
|
||||||
"""Fills in the next population with random chromosomes from the last population"""
|
"""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)]
|
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):
|
def fill_in_parents_then_random(ga):
|
||||||
"""Fills in the next population with all parents followed by random chromosomes from the last population"""
|
"""Fills in the next population with all parents followed by random chromosomes from the last population"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user