Fixed bug
Potentially 0 mutations occur
This commit is contained in:
@ -65,7 +65,7 @@ class Attributes:
|
|||||||
tolerance_goal = None,
|
tolerance_goal = None,
|
||||||
percent_converged = 0.50,
|
percent_converged = 0.50,
|
||||||
chromosome_mutation_rate = 0.15,
|
chromosome_mutation_rate = 0.15,
|
||||||
gene_mutation_rate = 0.10,
|
gene_mutation_rate = 0.05,
|
||||||
initialization_impl = Initialization_Methods.random_initialization,
|
initialization_impl = Initialization_Methods.random_initialization,
|
||||||
fitness_function_impl = Fitness_Examples.is_it_5,
|
fitness_function_impl = Fitness_Examples.is_it_5,
|
||||||
make_population = create_population,
|
make_population = create_population,
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import random
|
import random
|
||||||
|
from math import ceil
|
||||||
|
|
||||||
class Mutation_Methods:
|
class Mutation_Methods:
|
||||||
|
|
||||||
@ -9,7 +10,7 @@ class Mutation_Methods:
|
|||||||
"""Selects random chromosomes"""
|
"""Selects random chromosomes"""
|
||||||
|
|
||||||
# Loop until enough mutations occur
|
# Loop until enough mutations occur
|
||||||
for n in range(int(ga.population.size()*ga.chromosome_mutation_rate)):
|
for n in range(ceil(ga.population.size()*ga.chromosome_mutation_rate)):
|
||||||
index = random.randint(0, ga.population.size()-1)
|
index = random.randint(0, ga.population.size()-1)
|
||||||
ga.population.set_chromosome(ga.mutation_individual_impl(ga, ga.population.get_chromosome(index)), index)
|
ga.population.set_chromosome(ga.mutation_individual_impl(ga, ga.population.get_chromosome(index)), index)
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ class Mutation_Methods:
|
|||||||
"""Selects random chromosomes and self-crosses with parent"""
|
"""Selects random chromosomes and self-crosses with parent"""
|
||||||
|
|
||||||
# Loop until enough mutations occur
|
# Loop until enough mutations occur
|
||||||
for n in range(int(ga.population.size()*ga.chromosome_mutation_rate)):
|
for n in range(ceil(ga.population.size()*ga.chromosome_mutation_rate)):
|
||||||
index = random.randint(0, ga.population.size()-1)
|
index = random.randint(0, ga.population.size()-1)
|
||||||
chromosome = ga.population.get_chromosome(index)
|
chromosome = ga.population.get_chromosome(index)
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ class Mutation_Methods:
|
|||||||
chromosome = ga.make_chromosome(old_chromosome.get_gene_list())
|
chromosome = ga.make_chromosome(old_chromosome.get_gene_list())
|
||||||
|
|
||||||
# Loops until enough mutations occur
|
# Loops until enough mutations occur
|
||||||
for n in range(int(chromosome.size()*ga.gene_mutation_rate)):
|
for n in range(ceil(chromosome.size()*ga.gene_mutation_rate)):
|
||||||
index = random.randint(0, chromosome.size()-1)
|
index = random.randint(0, chromosome.size()-1)
|
||||||
|
|
||||||
# Using the chromosome_impl
|
# Using the chromosome_impl
|
||||||
@ -65,7 +66,7 @@ class Mutation_Methods:
|
|||||||
chromosome = ga.make_chromosome(old_chromosome.get_gene_list())
|
chromosome = ga.make_chromosome(old_chromosome.get_gene_list())
|
||||||
|
|
||||||
# Loops until enough mutations occur
|
# Loops until enough mutations occur
|
||||||
for n in range(int(chromosome.size()*ga.gene_mutation_rate)):
|
for n in range(ceil(chromosome.size()*ga.gene_mutation_rate)):
|
||||||
index_one = random.randint(0, chromosome.size()-1)
|
index_one = random.randint(0, chromosome.size()-1)
|
||||||
index_two = random.randint(0, chromosome.size()-1)
|
index_two = random.randint(0, chromosome.size()-1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user