Fixed import problems
This commit is contained in:
@ -4,14 +4,13 @@ import random
|
|||||||
from initialization import population as create_population
|
from initialization import population as create_population
|
||||||
from initialization import chromosome as create_chromosome
|
from initialization import chromosome as create_chromosome
|
||||||
from initialization import gene as create_gene
|
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
|
# Import functionality defaults
|
||||||
from initialization import random_initialization
|
from initialization import random_initialization
|
||||||
|
|
||||||
class GA:
|
class GA:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Initialize the GA."""
|
"""Initialize the GA."""
|
||||||
|
|
||||||
# Default variables
|
# Default variables
|
||||||
self.chromosome_impl = None
|
self.chromosome_impl = None
|
||||||
self.gene_impl = None
|
self.gene_impl = None
|
||||||
@ -43,20 +42,21 @@ class GA:
|
|||||||
self.gene_impl)
|
self.gene_impl)
|
||||||
|
|
||||||
def evolve(self):
|
def evolve(self):
|
||||||
"""Runs the ga until the ga is no longer active."""
|
"""Runs the ga until the termination point has been satisfied."""
|
||||||
while(self.active()):
|
self.initialize_population()
|
||||||
if(self.current_generation == 0):
|
#while(self.active()):
|
||||||
initialize_population()
|
#if(self.current_generation == 0):
|
||||||
|
#initialize_population()
|
||||||
|
|
||||||
get_fitness(population)
|
#get_fitness(population)
|
||||||
|
|
||||||
# run one iteration while the ga is active
|
# run one iteration while the ga is active
|
||||||
while self.active():
|
#while self.active():
|
||||||
self.evolve_generation(1)
|
#self.evolve_generation(1)
|
||||||
|
|
||||||
def active(self):
|
def active(self):
|
||||||
"""Returns if the ga should terminate or not"""
|
"""Returns if the ga should terminate base on the termination implimented"""
|
||||||
return self.termination_impl.active(self)
|
return self.termination_impl(self)
|
||||||
|
|
||||||
|
|
||||||
def evolve_generation(self, number_of_generations):
|
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 .population_structure.population import population
|
||||||
from .chromosome_structure.chromosome import chromosome
|
from .chromosome_structure.chromosome import chromosome
|
||||||
from .gene_structure.gene import gene
|
from .gene_structure.gene import gene
|
||||||
from .fitness_function import default_fitness_example
|
|
||||||
|
|||||||
@ -5,19 +5,12 @@ ga = EasyGA.GA()
|
|||||||
|
|
||||||
ga.chromosome_length = 3
|
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
|
# 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()
|
ga.evolve()
|
||||||
|
|
||||||
|
# Print the current population
|
||||||
ga.population.print_all()
|
ga.population.print_all()
|
||||||
|
|||||||
Reference in New Issue
Block a user