Fixed bug
Potentially 0 mutations occur
This commit is contained in:
@ -65,7 +65,7 @@ class Attributes:
|
||||
tolerance_goal = None,
|
||||
percent_converged = 0.50,
|
||||
chromosome_mutation_rate = 0.15,
|
||||
gene_mutation_rate = 0.10,
|
||||
gene_mutation_rate = 0.05,
|
||||
initialization_impl = Initialization_Methods.random_initialization,
|
||||
fitness_function_impl = Fitness_Examples.is_it_5,
|
||||
make_population = create_population,
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import random
|
||||
from math import ceil
|
||||
|
||||
class Mutation_Methods:
|
||||
|
||||
@ -9,7 +10,7 @@ class Mutation_Methods:
|
||||
"""Selects random chromosomes"""
|
||||
|
||||
# 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)
|
||||
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"""
|
||||
|
||||
# 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)
|
||||
chromosome = ga.population.get_chromosome(index)
|
||||
|
||||
@ -37,7 +38,7 @@ class Mutation_Methods:
|
||||
chromosome = ga.make_chromosome(old_chromosome.get_gene_list())
|
||||
|
||||
# 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)
|
||||
|
||||
# Using the chromosome_impl
|
||||
@ -65,7 +66,7 @@ class Mutation_Methods:
|
||||
chromosome = ga.make_chromosome(old_chromosome.get_gene_list())
|
||||
|
||||
# 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_two = random.randint(0, chromosome.size()-1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user