Major structural changes

This commit is contained in:
Daniel Wilczak
2020-09-23 16:46:59 -04:00
parent cd15a85b71
commit 2322a186e3
11 changed files with 24 additions and 28 deletions

View File

@ -1,15 +1,11 @@
# Import all the data structure onjects
from initialization.gene import gene
from initialization.chromosome import chromosome
from initialization.population import population
from initialization.random_gene import random_gene
# Import all the data prebuilt modules
from initialization.gene_creation.gene_random import random_gene
from initialization.random_initialization import random_initialization
class GA:
def __init__(self):
# Default variables
self.population = None
self.generations = 3
@ -17,7 +13,7 @@ class GA:
self.population_size = 5
self.mutation_rate = 0.03
# Defualt EastGA implimentation structure
self.gene_function_impl = random_gene(1,100)
self.gene_function_impl = random_gene
# Set the GA Configuration
self.initialization_impl = random_initialization()
#self.mutation_impl = PerGeneMutation(Mutation_rate)

View File

@ -9,7 +9,5 @@ def check_values(low,high):
assert high > low , "High value can not be smaller then low value"
assert high != 0, "High value can not be zero"
def random_gene(low,high):
# Check the values so that they follow the rules.
check_values(low,high)
def random_gene():
return random.randint(1,100)

View File

@ -1,3 +0,0 @@
class initialization:
def initialize(self,chromosome_length,population_size,gene_function):
return [] # return an array of chromosomes for generation 0

View File

@ -1,8 +1,8 @@
class population:
# population = [chromosome,chromosome,etc]
def __init__(self):
self.chromosomes = []
self.fitness = None
self.chromosomes = []
def add_chromosome(self,chromosome):
self.chromosomes.append(chromosome)

View File

@ -1,20 +1,23 @@
from initialization.population import population
from initialization.chromosome import chromosome
from initialization.gene import gene
# 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
from initialization.initialization import initialization
from .initialization import initialization
class random_initialization(initialization):
class random_initialization:
def initialize(self,chromosome_length,population_size,gene_function):
# I dont understand why python needs this in its scope but it does.
global population
global chromosome
global gene
# Create the population object
population = population.population()
population = create_population()
# Fill the population with chromosomes
for i in range(population_size):
chromosome = chromosome.chromosome()
chromosome = create_chromosome()
#Fill the Chromosome with genes
for j in range(chromosome_length):
gene = gene.gene(gene_function)
chromosome.add_gene(gene)
chromosome.add_gene(create_gene(gene_function()))
population.add_chromosome(chromosome)
return population

View File

@ -4,6 +4,8 @@ import EasyGA
# Create the Genetic algorithm
ga = EasyGA.GA()
# Start the population
ga.initialize()
ga.population.chromosome[0].print_chromosome()
for chromosome in ga.population.chromosomes:
print(chromosome.genes[0].__dict__)