Requested file name changes

This commit is contained in:
danielwilczak101
2020-09-30 23:25:44 -04:00
parent 8377650c58
commit aa0c5320c8
23 changed files with 96 additions and 72 deletions

View File

@ -4,13 +4,14 @@ import random
from initialization import population as create_population
from initialization import chromosome as create_chromosome
from initialization import gene as create_gene
# Import the default fitness function
from fitness_function import example_is_it_5
# Import default termination points
from termination_point import generation_based
from termination_point import fitness_based
# Import functionality defaults
from initialization import random_initialization
#
from fitness_function import fitness_examples
# Import example classes
from initialization import initialization_examples
from termination_point import termination_examples
from selection import selection_examples
from crossover import crossover_examples
from mutation import mutation_examples
class GA:
def __init__(self):
@ -31,12 +32,12 @@ class GA:
# Defualt EastGA implimentation structure
self.initialization_impl = random_initialization
self.fitness_funciton_impl = example_is_it_5
self.initialization_impl = initialization_examples.random_initialization
self.fitness_funciton_impl = fitness_examples.is_it_5
#self.mutation_impl = PerGeneMutation(Mutation_rate)
#self.selection_impl = TournamentSelection()
#self.crossover_impl = FastSinglePointCrossover()
self.termination_impl = generation_based
self.termination_impl = termination_examples.generation_based
# If we want the fitnesses to be updated by the computer
self.update_fitness = True

View File

@ -1 +1,2 @@
# From file name import function name
# FROM (. means local) file_name IMPORT function_name
from .examples import crossover_examples

View File

@ -0,0 +1,3 @@
class crossover_examples:
"""Crossover examples will go here """
pass

View File

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

View File

@ -1,13 +0,0 @@
def example_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.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

View File

@ -0,0 +1,16 @@
class fitness_examples:
"""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.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

View File

@ -1,5 +1,5 @@
# FROM (. means local) file_name IMPORT function_name
from .random_initialization import random_initialization
from .examples import initialization_examples
from .population_structure.population import population
from .chromosome_structure.chromosome import chromosome
from .gene_structure.gene import gene

View File

@ -0,0 +1,33 @@
# Import the data structure
from .population_structure.population import population as create_population
from .chromosome_structure.chromosome import chromosome as create_chromosome
from .gene_structure.gene import gene as create_gene
class initialization_examples:
"""Initialization examples that are used as defaults and examples"""
def random_initialization(population_size, chromosome_length, chromosome_impl, gene_impl):
"""Takes the initialization inputs and choregraphs them to output the type of population
with the given parameters."""
# Create the population object
population = create_population()
# Fill the population with chromosomes
for i in range(population_size):
chromosome = create_chromosome()
#Fill the Chromosome with genes
for j in range(chromosome_length):
# Using the chromosome_impl to set every index inside of the chromosome
if chromosome_impl != None:
# Each chromosome location is specified with its own function
chromosome.add_gene(create_gene(chromosome_impl(j)))
# Will break if chromosome_length != len(lists) in domain
elif gene_impl != None:
# gene_impl = [range function,lowerbound,upperbound]
function = gene_impl[0]
chromosome.add_gene(create_gene(function(*gene_impl[1:])))
else:
#Exit because either were not specified
print("Your domain or range were not specified")
population.add_chromosome(chromosome)
return population

View File

@ -1,30 +0,0 @@
# Import the data structure
from .population_structure.population import population as create_population
from .chromosome_structure.chromosome import chromosome as create_chromosome
from .gene_structure.gene import gene as create_gene
def random_initialization(population_size, chromosome_length, chromosome_impl, gene_impl):
"""Takes the initialization inputs and choregraphs them to output the type of population
with the given parameters."""
# Create the population object
population = create_population()
# Fill the population with chromosomes
for i in range(population_size):
chromosome = create_chromosome()
#Fill the Chromosome with genes
for j in range(chromosome_length):
# Using the chromosome_impl to set every index inside of the chromosome
if chromosome_impl != None:
# Each chromosome location is specified with its own function
chromosome.add_gene(create_gene(chromosome_impl(j)))
# Will break if chromosome_length != len(lists) in domain
elif gene_impl != None:
# gene_impl = [range function,lowerbound,upperbound]
function = gene_impl[0]
chromosome.add_gene(create_gene(function(*gene_impl[1:])))
else:
#Exit because either were not specified
print("Your domain or range were not specified")
population.add_chromosome(chromosome)
return population

View File

@ -0,0 +1,2 @@
# FROM (. means local) file_name IMPORT function_name
from .examples import mutation_examples

3
src/mutation/examples.py Normal file
View File

@ -0,0 +1,3 @@
class mutation_examples:
"""Selection examples will go here """
pass

View File

View File

@ -0,0 +1,2 @@
# FROM (. means local) file_name IMPORT function_name
from .examples import selection_examples

View File

@ -0,0 +1,3 @@
class selection_examples:
"""Selection examples will go here """
pass

View File

View File

@ -1,3 +1,2 @@
# FROM (. means local) file_name IMPORT function_name
from .generation_based import generation_based
from .fitness_based import fitness_based
# FROM (. means local) file_name IMPORT class name
from .examples import termination_examples

View File

@ -0,0 +1,16 @@
class termination_examples:
"""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.goal_fitness):
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.max_generations):
status = False
return status

View File

@ -1,5 +0,0 @@
def fitness_based(ga):
status = True
if(ga.current_fitness > ga.goal_fitness):
status = False
return status

View File

@ -1,7 +0,0 @@
def generation_based(ga):
"""Generation based approach to termination - If the current generation is
less then the """
status = True
if(ga.current_generation > ga.max_generations):
status = False
return status

View File