Decorators cleanly preserve both function names and doc-strings.

This commit is contained in:
SimpleArt
2020-12-27 10:11:43 -05:00
parent 44683c7fae
commit 2b6f0e2e97
5 changed files with 73 additions and 39 deletions

View File

@ -1,5 +1,8 @@
from EasyGA import function_info
import random
@function_info
def _check_selection_probability(selection_method):
"""Raises an exception if the selection_probability
is not between 0 and 1 inclusively. Otherwise runs
@ -16,6 +19,7 @@ def _check_selection_probability(selection_method):
return new_method
@function_info
def _check_positive_fitness(selection_method):
"""Raises an exception if the population contains a
chromosome with negative fitness. Otherwise runs
@ -32,6 +36,7 @@ def _check_positive_fitness(selection_method):
return new_method
@function_info
def _ensure_sorted(selection_method):
"""Sorts the population by fitness
and then runs the selection method.
@ -45,6 +50,7 @@ def _ensure_sorted(selection_method):
return new_method
@function_info
def _compute_parent_amount(selection_method):
"""Computes the amount of parents
needed to be selected, and passes it