file structure changes and testing files added.
This commit is contained in:
@ -1,28 +1,32 @@
|
|||||||
# Defult packages for GA functionality
|
# Defult packages for GA functionality
|
||||||
from initialization.random_initialization import random_initialization
|
from initialization.random_initialization import random_initialization
|
||||||
|
|
||||||
|
import random
|
||||||
|
from defaults import defaults
|
||||||
|
import gene
|
||||||
|
|
||||||
class GA:
|
class GA:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Default variables
|
# Default variables
|
||||||
self.population_size = defaults.generations
|
self.gene = defaults.default_gene_function()
|
||||||
self.chromosome_length = defaults.chromosome_length
|
# self.population_size = defaults.generations
|
||||||
self.generations = defaults.generations
|
# self.chromosome_length = defaults.chromosome_length
|
||||||
# Defualt ga implimentation structure
|
# self.generations = defaults.generations
|
||||||
self.create_gene = defaults.default_gene_function()
|
# # Defualt ga implimentation structure
|
||||||
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):
|
# self.initialization = defaults.default_initialize()
|
||||||
# Create the initial population
|
# self.mutation = defaults.default_mutations_function()
|
||||||
self.population = self.initialization.initialize(self.population_size,
|
# self.selection = defaults.default_selection_function()
|
||||||
self.chromosome_length,
|
# self.crossover = defaults.default_crossover_function()
|
||||||
self.user_gene_function)
|
# self.termination = defaults.default_termination_function(self.generations)
|
||||||
|
# self.fitness_function = defaults.default_fitness_function()
|
||||||
def evolve(self):
|
#
|
||||||
# Evolve will run all the functions
|
# def initialize(self):
|
||||||
initialize()
|
# # 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
|
# Defult values so that the user doesnt have to explicidly
|
||||||
# state every feature of the genetic algorithm.
|
# state every feature of the genetic algorithm.
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.generations = 3
|
self.generations = 3
|
||||||
self.chromosome_length = 4
|
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 random
|
||||||
import EasyGA
|
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
|
# Create the Genetic algorithm
|
||||||
ga = EasyGA.GA(Population_size, Chromosome_length,
|
ga = EasyGA.GA()
|
||||||
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()}")
|
|
||||||
|
|||||||
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