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:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user