file structure changes and testing files added.
This commit is contained in:
@ -1,28 +1,32 @@
|
||||
# Defult packages for GA functionality
|
||||
from initialization.random_initialization import random_initialization
|
||||
|
||||
import random
|
||||
from defaults import defaults
|
||||
import gene
|
||||
|
||||
class GA:
|
||||
def __init__(self):
|
||||
# Default variables
|
||||
self.population_size = defaults.generations
|
||||
self.chromosome_length = defaults.chromosome_length
|
||||
self.generations = defaults.generations
|
||||
# Defualt ga implimentation structure
|
||||
self.create_gene = defaults.default_gene_function()
|
||||
self.initialization = defaults.default_initialize()
|
||||
self.mutation = defaults.default_mutations_function()
|
||||
self.selection = defaults.default_selection_function()
|
||||
self.crossover = defaults.default_crossover_function()
|
||||
self.termination = defaults.default_termination_function(self.generations)
|
||||
self.fitness_function = defaults.default_fitness_function()
|
||||
self.gene = defaults.default_gene_function()
|
||||
# self.population_size = defaults.generations
|
||||
# self.chromosome_length = defaults.chromosome_length
|
||||
# self.generations = defaults.generations
|
||||
# # Defualt ga implimentation structure
|
||||
|
||||
def initialize(self):
|
||||
# Create the initial population
|
||||
self.population = self.initialization.initialize(self.population_size,
|
||||
self.chromosome_length,
|
||||
self.user_gene_function)
|
||||
|
||||
def evolve(self):
|
||||
# Evolve will run all the functions
|
||||
initialize()
|
||||
# self.initialization = defaults.default_initialize()
|
||||
# self.mutation = defaults.default_mutations_function()
|
||||
# self.selection = defaults.default_selection_function()
|
||||
# self.crossover = defaults.default_crossover_function()
|
||||
# self.termination = defaults.default_termination_function(self.generations)
|
||||
# self.fitness_function = defaults.default_fitness_function()
|
||||
#
|
||||
# def initialize(self):
|
||||
# # Create the initial population
|
||||
# self.population = self.initialization.initialize(self.population_size,
|
||||
# self.chromosome_length,
|
||||
# self.user_gene_function)
|
||||
#
|
||||
# def evolve(self):
|
||||
# # Evolve will run all the functions
|
||||
# initialize()
|
||||
|
||||
0
src/chromosome/chromosome_tests.py
Normal file
0
src/chromosome/chromosome_tests.py
Normal file
@ -1,8 +1,8 @@
|
||||
class defaults(self):
|
||||
import random
|
||||
|
||||
class defaults:
|
||||
# Defult values so that the user doesnt have to explicidly
|
||||
# state every feature of the genetic algorithm.
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.generations = 3
|
||||
self.chromosome_length = 4
|
||||
0
src/defaults/defaults_tests.py
Normal file
0
src/defaults/defaults_tests.py
Normal file
0
src/gene/gene_tests.py
Normal file
0
src/gene/gene_tests.py
Normal file
31
src/index.py
31
src/index.py
@ -1,34 +1,5 @@
|
||||
import random
|
||||
import EasyGA
|
||||
|
||||
# The user defined gene function
|
||||
def user_gene_function():
|
||||
return random.randint(1, 100)
|
||||
|
||||
# The user defined Fitness Function
|
||||
def user_fitness_function(chromosome):
|
||||
pass
|
||||
|
||||
# Standard user size requirements
|
||||
Population_size = 10
|
||||
Chromosome_length = 10
|
||||
|
||||
# Create the Genetic algorithm
|
||||
ga = EasyGA.GA(Population_size, Chromosome_length,
|
||||
user_gene_function,user_fitness_function)
|
||||
ga.initialize()
|
||||
|
||||
# Looking to print the first Chromosome
|
||||
ga.population.chromosomes[0].print_chromosome()
|
||||
|
||||
# Looking to print one gene in chromosome 0
|
||||
ga.population.chromosomes[0].genes[0].print_value()
|
||||
|
||||
# Looking to get the data of a chromosome
|
||||
my_chromosome = ga.population.chromosomes[0]
|
||||
print(f"my_chromosome: {my_chromosome.get_chromosome()}")
|
||||
print(f"my_chromosome fitness: {my_chromosome.get_fitness()}")
|
||||
# Looking to get the data of one gene in the chromosome
|
||||
my_gene = ga.population.chromosomes[0].genes[0]
|
||||
print(f"my_gene: {my_gene.get_value()}")
|
||||
print(f"my_gene fitness: {my_gene.get_fitness()}")
|
||||
ga = EasyGA.GA()
|
||||
|
||||
0
src/initialization/initialization_test.py
Normal file
0
src/initialization/initialization_test.py
Normal file
0
src/population/population_tests.py
Normal file
0
src/population/population_tests.py
Normal file
Reference in New Issue
Block a user