Structure change to make it easier for users to clone and use the repository.

This commit is contained in:
danielwilczak101
2021-01-26 21:20:38 -06:00
parent 92cea15a09
commit 2fc75aba07
43 changed files with 7 additions and 30 deletions

View File

@ -0,0 +1,46 @@
def is_it_5(self, chromosome):
"""A very simple case test function - If the chromosome's gene value
is equal to 5 add one to the chromosomes overall fitness value.
"""
# Overall fitness value
fitness = 0
for gene in chromosome:
# Increment fitness is the gene's value is 5
if gene.value == 5:
fitness += 1
return fitness
def near_5(self, chromosome):
"""Test's the GA's ability to handle floats. Computes how close each gene is to 5."""
# Overall fitness value
fitness = 0
for gene in chromosome:
# Add squared distance to 5
fitness += (5 - gene.value) ** 2
return fitness
def index_dependent_values(self, chromosome):
"""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.
"""
# Overall fitness value
fitness = 0
for i, gene in enumerate(chromosome):
# Increment fitness is the gene's value is i+1
if gene.value == i+1:
fitness += 1
return fitness

1
examples/README.md Normal file
View File

@ -0,0 +1 @@
# Fitness function

0
examples/__init__.py Normal file
View File

1
examples/test_methods.py Normal file
View File

@ -0,0 +1 @@