From ffb36c91fc009e62e530be86717ed4555683db9a Mon Sep 17 00:00:00 2001 From: SimpleArt <71458112+SimpleArt@users.noreply.github.com> Date: Sun, 13 Dec 2020 10:07:23 -0500 Subject: [PATCH] Avoid adapting on the first generation and catch wrong target fitness type --- src/EasyGA.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/EasyGA.py b/src/EasyGA.py index e3e6668..1f4295b 100644 --- a/src/EasyGA.py +++ b/src/EasyGA.py @@ -87,7 +87,7 @@ class GA(Attributes): # Adapt the ga if the generation times the adapt rate # passes through an integer value. adapt_counter = self.adapt_rate*self.current_generation - if int(adapt_counter) > int(adapt_counter - self.adapt_rate): + if int(adapt_counter) < int(adapt_counter + self.adapt_rate): self.adapt() number_of_generations -= 1 @@ -262,8 +262,11 @@ class GA(Attributes): etc. """ + if self.target_fitness_type not in ('max', 'min'): + raise ValueError("Unknown target fitness type") + if in_place: - chromosome_list.sort( # list to be sorted + chromosome_list.sort( # list to be sorted key = lambda chromosome: chromosome.fitness, # by fitness reverse = (self.target_fitness_type == 'max') # ordered by fitness type )