Added comments & fixed small bug

Mostly added comments, but also fixed a small bug in parent selection where the tournament size would be much smaller than it should be.
This commit is contained in:
RyleyGG
2020-10-12 09:23:41 -04:00
parent c3d9ef8bd1
commit 94d7c52666
7 changed files with 50 additions and 46 deletions

View File

@ -16,11 +16,9 @@ class Fitness_Examples:
return fitness
def index_dependent_values(chromosome):
"""A very simple case test function - If the chromosomes gene value is a 5 add one
to the chromosomes overall fitness value."""
# Overall fitness value
"""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"""
fitness = 0
# For each gene in the chromosome
for i in range(len(chromosome.gene_list)):
if (chromosome.gene_list[i].value == i+1):
fitness += 1