Fixed mutation to allow chromosome_impl generators under new framework
This commit is contained in:
@ -50,18 +50,7 @@ class Individual:
|
|||||||
@_loop_random_mutations
|
@_loop_random_mutations
|
||||||
def individual_genes(ga, chromosome, index):
|
def individual_genes(ga, chromosome, index):
|
||||||
"""Mutates random genes by making completely new genes."""
|
"""Mutates random genes by making completely new genes."""
|
||||||
|
chromosome[index] = ga.make_chromosome(ga.chromosome_impl())[index]
|
||||||
# Using the chromosome_impl
|
|
||||||
if ga.chromosome_impl is not None:
|
|
||||||
chromosome[index] = ga.make_gene(ga.chromosome_impl()[index])
|
|
||||||
|
|
||||||
# Using the gene_impl
|
|
||||||
elif ga.gene_impl is not None:
|
|
||||||
chromosome[index] = ga.make_gene(ga.gene_impl())
|
|
||||||
|
|
||||||
# Exit because no gene creation method specified
|
|
||||||
else:
|
|
||||||
raise Exception("Did not specify any initialization constraints.")
|
|
||||||
|
|
||||||
|
|
||||||
class Arithmetic:
|
class Arithmetic:
|
||||||
@ -77,18 +66,7 @@ class Individual:
|
|||||||
number of generations run."""
|
number of generations run."""
|
||||||
|
|
||||||
weight = 1/max(1, ga.current_generation)
|
weight = 1/max(1, ga.current_generation)
|
||||||
|
new_value = ga.make_chromosome(ga.chromosome_impl())[index]
|
||||||
# Using the chromosome_impl
|
|
||||||
if ga.chromosome_impl is not None:
|
|
||||||
new_value = ga.chromosome_impl()[index]
|
|
||||||
|
|
||||||
# Using the gene_impl
|
|
||||||
elif ga.gene_impl is not None:
|
|
||||||
new_value = ga.gene_impl()
|
|
||||||
|
|
||||||
# Exit because no gene creation method specified
|
|
||||||
else:
|
|
||||||
raise Exception("Did not specify any initialization constraints.")
|
|
||||||
|
|
||||||
chromosome[index] = ga.make_gene((1-weight)*chromosome[index].value + weight*new_value)
|
chromosome[index] = ga.make_gene((1-weight)*chromosome[index].value + weight*new_value)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user