Added blank lines and fixed run_testing

This commit is contained in:
SimpleArt
2020-10-12 19:57:57 -04:00
parent 4770473825
commit 3424fd4da7
9 changed files with 86 additions and 18 deletions

View File

@ -3,15 +3,23 @@ class Termination_Methods:
def fitness_based(ga):
"""Fitness based approach to terminate when the goal fitness has been reached"""
# Need to start the algorithm if the population is None
if ga.population == None:
return True
for i in range(ga.population.size()):
if(ga.population.get_all_chromosomes()[i].fitness >= ga.fitness_goal):
# Check all chromosomes
for chromosome in ga.population.get_all_chromosomes():
# Stop if a chromosome has reached the fitness_goal
if(chromosome.fitness >= ga.fitness_goal):
return False
# Continue if no chromosomes have reached the fitness goal
return True
def generation_based(ga):
"""Generation based approach to terminate when the goal generation has been reached"""
return ga.current_generation < ga.generation_goal