Test Implementation for selection/crossover/mutation

The current test implementation includes random mutation, single point crossover, and tournament selection. The implementation, in short, is a nested approach. The selection method is the only thing actually called by the GA. Both crossover and mutation occur within the selection method. As long as these three systems all follow a standard input/output system, any implementation we build, as well as any user implementations, will work perfectly. The selection function must take GA as a parameter and output a new population. Crossover takes in GA and outputs a population. Mutation takes a chromosome set and outputs a new chromosome set.

Many of the changes in this commit are regarding this test implementation. I have also changed many of the file names from "x_examples" to "x_types" and updated the class names to follow capitalziation standards. I did this because I feel personally like the built-in mutation, crossover, and selection implementations are less "examples" and more just already built implementations to make the code required from the user smaller.
This commit is contained in:
Ryley
2020-10-04 08:00:33 -04:00
parent 6aec9770b6
commit 7e587d48d0
17 changed files with 364 additions and 1 deletions

View File

@ -0,0 +1,2 @@
# FROM (. means local) file_name IMPORT class name
from .examples import Fitness_Examples

View File

@ -0,0 +1,17 @@
class Fitness_Examples:
"""Fitness function examples used"""
def is_it_5(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 gene in chromosome.genes:
# Check if its value = 5
if(gene.value == 5):
# If its value is 5 then add one to
# the overal fitness of the chromosome.
fitness += 1
return fitness