Merge pull request #8 from danielwilczak101/Dans_devel
Changed names of impl
This commit is contained in:
@ -11,8 +11,8 @@ from initialization.random_initialization import random_initialization
|
||||
class GA:
|
||||
def __init__(self):
|
||||
# Default variables
|
||||
self.domain = None
|
||||
self.new_range = None
|
||||
self.chromosome_impl = None
|
||||
self.gene_impl = None
|
||||
self.population = None
|
||||
self.generations = 3
|
||||
self.chromosome_length = 3
|
||||
@ -30,8 +30,8 @@ class GA:
|
||||
self.population = self.initialization_impl(
|
||||
self.population_size,
|
||||
self.chromosome_length,
|
||||
self.domain,
|
||||
self.new_range)
|
||||
self.chromosome_impl,
|
||||
self.gene_impl)
|
||||
|
||||
def evolve():
|
||||
# If you just want to evolve through all generations
|
||||
|
||||
@ -3,7 +3,7 @@ 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
|
||||
|
||||
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
|
||||
population = create_population()
|
||||
# Fill the population with chromosomes
|
||||
@ -11,14 +11,14 @@ def random_initialization(population_size, chromosome_length, domain, new_range)
|
||||
chromosome = create_chromosome()
|
||||
#Fill the Chromosome with genes
|
||||
for j in range(chromosome_length):
|
||||
if domain != None:
|
||||
if chromosome_impl != None:
|
||||
# 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
|
||||
elif new_range != None:
|
||||
# new_rnage = [range function,lowerbound,upperbound]
|
||||
function = new_range[0]
|
||||
chromosome.add_gene(create_gene(function(new_range[1],new_range[2])))
|
||||
elif gene_impl != None:
|
||||
# gene_impl = [range function,lowerbound,upperbound]
|
||||
function = gene_impl[0]
|
||||
chromosome.add_gene(create_gene(function(gene_impl[1],gene_impl[2])))
|
||||
else:
|
||||
#Exit because either were not specified
|
||||
print("Your domain or range were not specified")
|
||||
|
||||
@ -1,26 +1,20 @@
|
||||
import EasyGA
|
||||
import random
|
||||
|
||||
# Create the Genetic algorithm
|
||||
ga = EasyGA.GA()
|
||||
|
||||
def user_gene_domain(gene_index):
|
||||
"""Each gene index is assosiated to its index in the chromosome"""
|
||||
domain = [
|
||||
random.randrange(1,100,5),
|
||||
chromosome = [
|
||||
random.randrange(1,100),
|
||||
random.uniform(10,5),
|
||||
random.choice(["up","down"])
|
||||
]
|
||||
return domain[gene_index]
|
||||
|
||||
print(user_gene_domain(0))
|
||||
return chromosome[gene_index]
|
||||
|
||||
# If the user wants to use a domain
|
||||
ga.domain = user_gene_domain
|
||||
# If the user wants to use a custom range
|
||||
#ga.new_range = [random.randrange,1,100,None]
|
||||
ga.chromosome_impl = user_gene_domain
|
||||
|
||||
ga.initialize()
|
||||
|
||||
#ga.population.print_all()
|
||||
|
||||
ga.population.print_all()
|
||||
|
||||
Reference in New Issue
Block a user