Requested file name changes
This commit is contained in:
@ -4,13 +4,14 @@ import random
|
|||||||
from initialization import population as create_population
|
from initialization import population as create_population
|
||||||
from initialization import chromosome as create_chromosome
|
from initialization import chromosome as create_chromosome
|
||||||
from initialization import gene as create_gene
|
from initialization import gene as create_gene
|
||||||
# Import the default fitness function
|
#
|
||||||
from fitness_function import example_is_it_5
|
from fitness_function import fitness_examples
|
||||||
# Import default termination points
|
# Import example classes
|
||||||
from termination_point import generation_based
|
from initialization import initialization_examples
|
||||||
from termination_point import fitness_based
|
from termination_point import termination_examples
|
||||||
# Import functionality defaults
|
from selection import selection_examples
|
||||||
from initialization import random_initialization
|
from crossover import crossover_examples
|
||||||
|
from mutation import mutation_examples
|
||||||
|
|
||||||
class GA:
|
class GA:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -31,12 +32,12 @@ class GA:
|
|||||||
|
|
||||||
|
|
||||||
# Defualt EastGA implimentation structure
|
# Defualt EastGA implimentation structure
|
||||||
self.initialization_impl = random_initialization
|
self.initialization_impl = initialization_examples.random_initialization
|
||||||
self.fitness_funciton_impl = example_is_it_5
|
self.fitness_funciton_impl = fitness_examples.is_it_5
|
||||||
#self.mutation_impl = PerGeneMutation(Mutation_rate)
|
#self.mutation_impl = PerGeneMutation(Mutation_rate)
|
||||||
#self.selection_impl = TournamentSelection()
|
#self.selection_impl = TournamentSelection()
|
||||||
#self.crossover_impl = FastSinglePointCrossover()
|
#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
|
# If we want the fitnesses to be updated by the computer
|
||||||
self.update_fitness = True
|
self.update_fitness = True
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
# From file name import function name
|
# FROM (. means local) file_name IMPORT function_name
|
||||||
|
from .examples import crossover_examples
|
||||||
|
|||||||
3
src/crossover/examples.py
Normal file
3
src/crossover/examples.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class crossover_examples:
|
||||||
|
"""Crossover examples will go here """
|
||||||
|
pass
|
||||||
@ -1,2 +1,2 @@
|
|||||||
# FROM (. means local) file_name IMPORT function_name
|
# FROM (. means local) file_name IMPORT class name
|
||||||
from .example_is_it_5 import example_is_it_5
|
from .examples import fitness_examples
|
||||||
|
|||||||
@ -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
|
|
||||||
16
src/fitness_function/examples.py
Normal file
16
src/fitness_function/examples.py
Normal 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
|
||||||
@ -1,5 +1,5 @@
|
|||||||
# FROM (. means local) file_name IMPORT function_name
|
# 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 .population_structure.population import population
|
||||||
from .chromosome_structure.chromosome import chromosome
|
from .chromosome_structure.chromosome import chromosome
|
||||||
from .gene_structure.gene import gene
|
from .gene_structure.gene import gene
|
||||||
|
|||||||
33
src/initialization/examples.py
Normal file
33
src/initialization/examples.py
Normal 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
|
||||||
@ -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
|
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
# FROM (. means local) file_name IMPORT function_name
|
||||||
|
from .examples import mutation_examples
|
||||||
|
|||||||
3
src/mutation/examples.py
Normal file
3
src/mutation/examples.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class mutation_examples:
|
||||||
|
"""Selection examples will go here """
|
||||||
|
pass
|
||||||
0
src/mutation/test_examples.py
Normal file
0
src/mutation/test_examples.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# FROM (. means local) file_name IMPORT function_name
|
||||||
|
from .examples import selection_examples
|
||||||
|
|||||||
3
src/selection/examples.py
Normal file
3
src/selection/examples.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class selection_examples:
|
||||||
|
"""Selection examples will go here """
|
||||||
|
pass
|
||||||
0
src/selection/test_examples.py
Normal file
0
src/selection/test_examples.py
Normal file
@ -1,3 +1,2 @@
|
|||||||
# FROM (. means local) file_name IMPORT function_name
|
# FROM (. means local) file_name IMPORT class name
|
||||||
from .generation_based import generation_based
|
from .examples import termination_examples
|
||||||
from .fitness_based import fitness_based
|
|
||||||
|
|||||||
16
src/termination_point/examples.py
Normal file
16
src/termination_point/examples.py
Normal 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
|
||||||
@ -1,5 +0,0 @@
|
|||||||
def fitness_based(ga):
|
|
||||||
status = True
|
|
||||||
if(ga.current_fitness > ga.goal_fitness):
|
|
||||||
status = False
|
|
||||||
return status
|
|
||||||
@ -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
|
|
||||||
0
src/termination_point/test_examples.py
Normal file
0
src/termination_point/test_examples.py
Normal file
Reference in New Issue
Block a user