Updated gene impl
This commit is contained in:
@ -12,16 +12,15 @@ class Initialization_Methods:
|
||||
if ga.chromosome_impl != None:
|
||||
return ga.make_population([
|
||||
ga.make_chromosome([
|
||||
ga.make_gene(ga.chromosome_impl(j))
|
||||
for j in range(ga.chromosome_length)])
|
||||
ga.make_gene(value)
|
||||
for value in ga.chromosome_impl()])
|
||||
for i in range(ga.population_size)])
|
||||
|
||||
# Using the gene_impl to set every gene to be the same
|
||||
elif ga.gene_impl != None:
|
||||
function = ga.gene_impl[0]
|
||||
return ga.make_population([
|
||||
ga.make_chromosome([
|
||||
ga.make_gene(function(*ga.gene_impl[1:]))
|
||||
ga.make_gene(ga.gene_impl())
|
||||
for j in range(ga.chromosome_length)])
|
||||
for i in range(ga.population_size)])
|
||||
|
||||
|
||||
@ -25,14 +25,13 @@ class Mutation_Methods:
|
||||
# Using the chromosome_impl to set every index inside of the chromosome
|
||||
if ga.chromosome_impl != None:
|
||||
return ga.make_chromosome([
|
||||
ga.make_gene(ga.chromosome_impl(j))
|
||||
for j in range(chromosome.size())])
|
||||
ga.make_gene(value)
|
||||
for value in ga.chromosome_impl()])
|
||||
|
||||
# Using the gene_impl
|
||||
elif ga.gene_impl != None:
|
||||
function = ga.gene_impl[0]
|
||||
return ga.make_chromosome([
|
||||
ga.make_gene(function(*ga.gene_impl[1:]))
|
||||
ga.make_gene(ga.gene_impl())
|
||||
for j in range(chromosome.size())])
|
||||
|
||||
# Exit because no gene creation method specified
|
||||
@ -48,13 +47,12 @@ class Mutation_Methods:
|
||||
# Using the chromosome_impl
|
||||
if ga.chromosome_impl != None:
|
||||
index = random.randint(0, chromosome.size()-1)
|
||||
chromosome.set_gene(ga.make_gene(ga.chromosome_impl(index)), index)
|
||||
chromosome.set_gene(ga.make_gene(ga.chromosome_impl()[index]), index)
|
||||
|
||||
# Using the gene_impl
|
||||
elif ga.gene_impl != None:
|
||||
function = ga.gene_impl[0]
|
||||
index = random.randint(0, chromosome.size()-1)
|
||||
chromosome.set_gene(ga.make_gene(function(*ga.gene_impl[1:])), index)
|
||||
chromosome.set_gene(ga.make_gene(ga.gene_impl()), index)
|
||||
|
||||
# Exit because no gene creation method specified
|
||||
else:
|
||||
|
||||
@ -3,9 +3,9 @@ import EasyGA
|
||||
|
||||
# Create the Genetic algorithm
|
||||
ga = EasyGA.GA()
|
||||
ga.population_size = 25
|
||||
ga.population_size = 100
|
||||
ga.generation_goal = 100
|
||||
ga.gene_impl = [random.randint,0,10]
|
||||
ga.gene_impl = lambda: random.randint(1, 10)
|
||||
ga.selection_probability = 0.5
|
||||
ga.fitness_function_impl = EasyGA.Fitness_Examples.near_5
|
||||
ga.parent_selection_impl = EasyGA.Parent_Selection.Roulette.stochastic_selection
|
||||
|
||||
Reference in New Issue
Block a user