Update EasyGA.py

Probably better to let fitness-based selection to work as expected than to break due to unexpected negatives.
This commit is contained in:
SimpleArt
2020-12-02 17:06:15 -05:00
parent 6f2392234d
commit fb84ac40d4

View File

@ -254,13 +254,7 @@ class GA(Attributes):
max_fitness = self.population[-1].fitness
min_fitness = self.population[0].fitness
# Avoid catastrophic cancellation
if min_fitness / max_fitness < 1e-5:
return -fitness_value
# Otherwise flip values
else:
return max_fitness - fitness_value + min_fitness
return max_fitness - fitness_value + min_fitness
def print_generation(self):