rewrote test fitness funciton

This commit is contained in:
danielwilczak101
2020-09-22 18:54:03 -04:00
parent 7aee6b9c8a
commit 2c3ef3f589
2 changed files with 17 additions and 1 deletions

View File

@ -0,0 +1,12 @@
class test_fitness_funciton:
def get_fitness(self, chromosome):
# For every gene in chromosome
for i in range(len(chromosome.genes)):
# If the gene has a five then add one to the fitness
# Example -> Chromosome = [5],[2],[2],[5],[5] then fitness = 3
if (chromosome.genes[i].get_value == 5):
# Add to the genes fitness
chromosome.genes[i].fitness += 1
# Add to the chromosomes fitness
chromosome.fitness += 1
return chromosome.fitness