diff --git a/src/fitness_function/fitness_examples.py b/src/fitness_function/fitness_examples.py index ce556d7..33e4730 100644 --- a/src/fitness_function/fitness_examples.py +++ b/src/fitness_function/fitness_examples.py @@ -7,7 +7,7 @@ class Fitness_Examples: # Overall fitness value fitness = 0 # For each gene in the chromosome - for gene in chromosome.gene_list: + for gene in chromosome: # Check if its value = 5 if(gene.value == 5): # If its value is 5 then add one to @@ -21,7 +21,7 @@ class Fitness_Examples: """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()]) + return sum([1-pow(1-gene.value/5, 2) for gene in chromosome]) def index_dependent_values(chromosome): @@ -29,8 +29,8 @@ class Fitness_Examples: If a gene is equal to its index in the chromosome + 1, fitness is incremented. """ fitness = 0 - for i in range(chromosome.size()): - if (chromosome.gene_list[i].value == i+1): + for i in range(len(chromosome)): + if (chromosome[i].value == i+1): fitness += 1 return fitness