Merge branch 'master' into ryley_beta
This commit is contained in:
16
src/fitness_function/methods.py
Normal file
16
src/fitness_function/methods.py
Normal file
@ -0,0 +1,16 @@
|
||||
class Fitness_methods:
|
||||
"""Fitness function examples used"""
|
||||
|
||||
def is_it_5(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.gene_list:
|
||||
# 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
|
||||
@ -1,12 +0,0 @@
|
||||
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
|
||||
1
src/fitness_function/test_methods.py
Normal file
1
src/fitness_function/test_methods.py
Normal file
@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user