Merge pull request #8 from danielwilczak101/Dans_devel

Changed names of impl
This commit is contained in:
danielwilczak101
2020-09-27 16:42:03 -04:00
committed by GitHub
3 changed files with 16 additions and 22 deletions

View File

@ -11,8 +11,8 @@ from initialization.random_initialization import random_initialization
class GA: class GA:
def __init__(self): def __init__(self):
# Default variables # Default variables
self.domain = None self.chromosome_impl = None
self.new_range = None self.gene_impl = None
self.population = None self.population = None
self.generations = 3 self.generations = 3
self.chromosome_length = 3 self.chromosome_length = 3
@ -30,8 +30,8 @@ class GA:
self.population = self.initialization_impl( self.population = self.initialization_impl(
self.population_size, self.population_size,
self.chromosome_length, self.chromosome_length,
self.domain, self.chromosome_impl,
self.new_range) self.gene_impl)
def evolve(): def evolve():
# If you just want to evolve through all generations # If you just want to evolve through all generations

View File

@ -3,7 +3,7 @@ from .population_structure.population import population as create_population
from .chromosome_structure.chromosome import chromosome as create_chromosome from .chromosome_structure.chromosome import chromosome as create_chromosome
from .gene_structure.gene import gene as create_gene from .gene_structure.gene import gene as create_gene
def random_initialization(population_size, chromosome_length, domain, new_range): def random_initialization(population_size, chromosome_length, chromosome_impl, gene_impl):
# Create the population object # Create the population object
population = create_population() population = create_population()
# Fill the population with chromosomes # Fill the population with chromosomes
@ -11,14 +11,14 @@ def random_initialization(population_size, chromosome_length, domain, new_range)
chromosome = create_chromosome() chromosome = create_chromosome()
#Fill the Chromosome with genes #Fill the Chromosome with genes
for j in range(chromosome_length): for j in range(chromosome_length):
if domain != None: if chromosome_impl != None:
# Each chromosome location is specified with its own function # Each chromosome location is specified with its own function
chromosome.add_gene(create_gene(domain(j))) chromosome.add_gene(create_gene(chromosome_impl(j)))
# Will break if chromosome_length != lists in domain # Will break if chromosome_length != lists in domain
elif new_range != None: elif gene_impl != None:
# new_rnage = [range function,lowerbound,upperbound] # gene_impl = [range function,lowerbound,upperbound]
function = new_range[0] function = gene_impl[0]
chromosome.add_gene(create_gene(function(new_range[1],new_range[2]))) chromosome.add_gene(create_gene(function(gene_impl[1],gene_impl[2])))
else: else:
#Exit because either were not specified #Exit because either were not specified
print("Your domain or range were not specified") print("Your domain or range were not specified")

View File

@ -1,26 +1,20 @@
import EasyGA import EasyGA
import random import random
# Create the Genetic algorithm # Create the Genetic algorithm
ga = EasyGA.GA() ga = EasyGA.GA()
def user_gene_domain(gene_index): def user_gene_domain(gene_index):
"""Each gene index is assosiated to its index in the chromosome""" """Each gene index is assosiated to its index in the chromosome"""
domain = [ chromosome = [
random.randrange(1,100,5), random.randrange(1,100),
random.uniform(10,5), random.uniform(10,5),
random.choice(["up","down"]) random.choice(["up","down"])
] ]
return domain[gene_index] return chromosome[gene_index]
print(user_gene_domain(0))
# If the user wants to use a domain # If the user wants to use a domain
ga.domain = user_gene_domain ga.chromosome_impl = user_gene_domain
# If the user wants to use a custom range
#ga.new_range = [random.randrange,1,100,None]
ga.initialize() ga.initialize()
#ga.population.print_all() ga.population.print_all()