Added gene mutation rate

This commit is contained in:
SimpleArt
2020-10-27 17:32:40 -04:00
parent 0b5f42966c
commit 00af4dbbe7
3 changed files with 39 additions and 24 deletions

View File

@ -4,13 +4,16 @@ import EasyGA
# Create the Genetic algorithm
ga = EasyGA.GA()
# Mutate and reproduce frequently
ga.parent_ratio = 0.25
ga.mutation_rate = 0.25
# Reproduce 30% of the population.
# Mutate 20% of the population.
# Mutate 3% of the genes in each mutated chromosome.
ga.parent_ratio = 0.30
ga.chromosome_mutation_rate = 0.20
ga.gene_mutation_rate = 0.03
# Create 25 chromosomes each with 10 genes
ga.population_size = 50
ga.chromosome_length = 10
ga.population_size = 100
ga.chromosome_length = 25
# Create random genes from 0 to 10
ga.gene_impl = lambda: random.randint(0, 10)
@ -21,7 +24,7 @@ ga.target_fitness_type = 'min'
# Terminate when a chromosome has all 0's
ga.fitness_goal = 0
ga.generation_goal = None
ga.generation_goal = 150
while ga.active():
ga.evolve_generation(10)