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

@ -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