Optimizations/updates

1. Deleted duplicate functions in EasyGA
2. Added new index-dependent fitness example
3. GA now auto-sorts by best fitness immediately after the fitness is calculated across the board
4. Removed 'selected' status flag from the Chromosome flag
5. Added mating_pool attribute to the population
6. Changed other code to be in line with 4 and 5
7. Optimized tournament selection method
This commit is contained in:
RyleyGG
2020-10-06 17:55:17 -04:00
parent 3bfa962194
commit e7ac0e23f4
7 changed files with 61 additions and 104 deletions

View File

@ -14,3 +14,15 @@ class Fitness_Examples:
fitness += 1
return fitness
def index_dependent_values(self, 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
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
return fitness