Fixed termination related stuff
This commit is contained in:
@ -17,7 +17,7 @@ ga.target_fitness_type = 'min'
|
||||
|
||||
# Terminate when a chromosome has all 0's
|
||||
ga.fitness_goal = 0
|
||||
ga.termination_impl = EasyGA.Termination_Methods.fitness_based
|
||||
ga.generation_goal = None
|
||||
|
||||
ga.evolve()
|
||||
|
||||
|
||||
@ -8,13 +8,16 @@ class Termination_Methods:
|
||||
if ga.population == None:
|
||||
return True
|
||||
|
||||
# If minimum fitness goal reached, stop ga.
|
||||
if ga.target_fitness_type == 'min' and ga.get_chromosome_fitness(0) >= ga.convert_fitness(ga.fitness_goal):
|
||||
return False
|
||||
# If fitness goal is set, check it.
|
||||
if ga.fitness_goal is not None:
|
||||
|
||||
# If maximum fitness goal reached, stop ga.
|
||||
if ga.target_fitness_type == 'max' and ga.get_chromosome_fitness(0) >= ga.convert_fitness(ga.fitness_goal):
|
||||
return False
|
||||
# If minimum fitness goal reached, stop ga.
|
||||
if ga.target_fitness_type == 'min' and ga.get_chromosome_fitness(0) >= ga.convert_fitness(ga.fitness_goal):
|
||||
return False
|
||||
|
||||
# Otherwise continue ga.
|
||||
return ga.current_generation < ga.generation_goal
|
||||
# If maximum fitness goal reached, stop ga.
|
||||
if ga.target_fitness_type == 'max' and ga.get_chromosome_fitness(0) >= ga.convert_fitness(ga.fitness_goal):
|
||||
return False
|
||||
|
||||
# If generation goal is set, check it.
|
||||
return ga.generation_goal is not None and ga.current_generation < ga.generation_goal
|
||||
|
||||
Reference in New Issue
Block a user