Fixed import problems
This commit is contained in:
@ -4,14 +4,13 @@ import random
|
||||
from initialization import population as create_population
|
||||
from initialization import chromosome as create_chromosome
|
||||
from initialization import gene as create_gene
|
||||
from fitness_function import default_fitness_example as default_fitness_example
|
||||
from fitness_function import default_fitness_example
|
||||
# Import functionality defaults
|
||||
from initialization import random_initialization
|
||||
|
||||
class GA:
|
||||
def __init__(self):
|
||||
"""Initialize the GA."""
|
||||
|
||||
# Default variables
|
||||
self.chromosome_impl = None
|
||||
self.gene_impl = None
|
||||
@ -43,20 +42,21 @@ class GA:
|
||||
self.gene_impl)
|
||||
|
||||
def evolve(self):
|
||||
"""Runs the ga until the ga is no longer active."""
|
||||
while(self.active()):
|
||||
if(self.current_generation == 0):
|
||||
initialize_population()
|
||||
"""Runs the ga until the termination point has been satisfied."""
|
||||
self.initialize_population()
|
||||
#while(self.active()):
|
||||
#if(self.current_generation == 0):
|
||||
#initialize_population()
|
||||
|
||||
get_fitness(population)
|
||||
#get_fitness(population)
|
||||
|
||||
# run one iteration while the ga is active
|
||||
while self.active():
|
||||
self.evolve_generation(1)
|
||||
#while self.active():
|
||||
#self.evolve_generation(1)
|
||||
|
||||
def active(self):
|
||||
"""Returns if the ga should terminate or not"""
|
||||
return self.termination_impl.active(self)
|
||||
"""Returns if the ga should terminate base on the termination implimented"""
|
||||
return self.termination_impl(self)
|
||||
|
||||
|
||||
def evolve_generation(self, number_of_generations):
|
||||
|
||||
@ -0,0 +1 @@
|
||||
from .default_fitness_example import default_fitness_example
|
||||
|
||||
@ -3,4 +3,3 @@ from .random_initialization import random_initialization
|
||||
from .population_structure.population import population
|
||||
from .chromosome_structure.chromosome import chromosome
|
||||
from .gene_structure.gene import gene
|
||||
from .fitness_function import default_fitness_example
|
||||
|
||||
@ -5,19 +5,12 @@ ga = EasyGA.GA()
|
||||
|
||||
ga.chromosome_length = 3
|
||||
|
||||
def user_gene_domain(gene_index):
|
||||
"""Each gene index is assosiated to its index in the chromosome"""
|
||||
chromosome = [
|
||||
# Gene instructions set here
|
||||
random.randrange(1,100),
|
||||
random.uniform(10,5),
|
||||
random.choice(["up","down"])
|
||||
]
|
||||
return chromosome[gene_index]
|
||||
|
||||
# If the user wants to use a domain
|
||||
ga.chromosome_impl = user_gene_domain
|
||||
ga.gene_impl = [random.randrange,1,10]
|
||||
|
||||
|
||||
# Run Everyhting
|
||||
ga.evolve()
|
||||
|
||||
# Print the current population
|
||||
ga.population.print_all()
|
||||
|
||||
Reference in New Issue
Block a user