Fixed decorator name issue and default weight

This commit is contained in:
SimpleArt
2020-12-26 15:19:19 -05:00
parent 5d88de1195
commit adbfdd4dbe

View File

@ -9,11 +9,14 @@ def _append_to_next_population(population_method):
Also modifies the input to include the mating pool. Also modifies the input to include the mating pool.
""" """
return lambda ga:\ def new_method(ga):
ga.population.append_children( ga.population.append_children(
population_method(ga, ga.population.mating_pool) population_method(ga, ga.population.mating_pool)
) )
new_method.__name__ = population_method.__name__
return new_method
def _check_weight(individual_method): def _check_weight(individual_method):
"""Checks if the weight is between 0 and 1 before running. """Checks if the weight is between 0 and 1 before running.
@ -21,7 +24,7 @@ def _check_weight(individual_method):
the error and try again with valid weight. the error and try again with valid weight.
""" """
def new_method(ga, parent_1, parent_2, weight): def new_method(ga, parent_1, parent_2, weight = 0.5):
if 0 < weight < 1: if 0 < weight < 1:
return individual_method(ga, parent_1, parent_2, weight) return individual_method(ga, parent_1, parent_2, weight)
@ -29,6 +32,7 @@ def _check_weight(individual_method):
raise ValueError("""Weight must be between 0 and 1 when using raise ValueError("""Weight must be between 0 and 1 when using
the given crossover method.""") the given crossover method.""")
new_method.__name__ = individual_method.__name__
return new_method return new_method
@ -55,7 +59,6 @@ class Crossover_Methods:
ga, # ga, #
mating_pool[index], # the parent and mating_pool[index], # the parent and
mating_pool[index-1], # the previous parent mating_pool[index-1], # the previous parent
0.5 # with equal weight
) )
@ -70,7 +73,6 @@ class Crossover_Methods:
ga, # ga, #
parent, # the parent and parent, # the parent and
random.choice(mating_pool), # a random parent random.choice(mating_pool), # a random parent
0.5 # with equal weight
) )