File name changes to match the rest of framework. generation goal was setup twice in EasyGA.
This commit is contained in:
@ -32,9 +32,8 @@ class GA:
|
||||
|
||||
# Termination variables
|
||||
self.current_generation = 0
|
||||
self.generation_goal = 50
|
||||
|
||||
self.current_fitness = 0
|
||||
|
||||
self.generation_goal = 250
|
||||
self.fitness_goal = 9
|
||||
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
class Crossover_methods:
|
||||
"""Mutation examples will go here """
|
||||
pass
|
||||
@ -1,16 +0,0 @@
|
||||
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,3 +0,0 @@
|
||||
class Mutation_methods:
|
||||
"""Mutation examples will go here """
|
||||
pass
|
||||
@ -1,2 +1,2 @@
|
||||
# FROM (. means local) file_name IMPORT function_name
|
||||
from .parent_selection import Parent_Selection
|
||||
from .parent_selection_methods import Parent_Selection
|
||||
|
||||
@ -13,4 +13,5 @@ ga.gene_impl = [random.randrange,1,100]
|
||||
ga.evolve()
|
||||
|
||||
# Print the current population
|
||||
print(f"Current Generation: {ga.current_generation}")
|
||||
ga.population.print_all()
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
# FROM (. means local) file_name IMPORT function_name
|
||||
from .survivor_selection import Survivor_Selection
|
||||
from .survivor_selection_methods import Survivor_Selection
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
class Termination_methods:
|
||||
"""Example functions that can be used to terminate the the algorithms loop"""
|
||||
|
||||
def fitness_based(ga):
|
||||
"""Fitness based approach to terminate when the goal fitness has been reached"""
|
||||
status = True
|
||||
if(ga.current_fitness > ga.fitness_goal):
|
||||
status = False
|
||||
return status
|
||||
|
||||
def generation_based(ga):
|
||||
"""Generation based approach to terminate when the goal generation has been reached"""
|
||||
status = True
|
||||
if(ga.current_generation > ga.generation_goal):
|
||||
status = False
|
||||
return status
|
||||
Reference in New Issue
Block a user