Fixed method names and added some crossover methods and tests for floats

This commit is contained in:
SimpleArt
2020-10-13 21:07:05 -04:00
parent b966b22b04
commit 0090db9dce
7 changed files with 89 additions and 36 deletions

View File

@ -17,6 +17,13 @@ class Fitness_Examples:
return fitness
def near_5(chromosome):
"""Test's the GA's ability to handle floats.
Computes how close each gene is to 5.
"""
return sum([1-pow(1-gene.get_value()/5, 2) for gene in chromosome.get_gene_list()])
def index_dependent_values(chromosome):
"""Test of the GA's ability to improve fitness when the value is index-dependent.
If a gene is equal to its index in the chromosome + 1, fitness is incremented.