Avoid adapting on the first generation and catch wrong target fitness type
This commit is contained in:
@ -87,7 +87,7 @@ class GA(Attributes):
|
|||||||
# Adapt the ga if the generation times the adapt rate
|
# Adapt the ga if the generation times the adapt rate
|
||||||
# passes through an integer value.
|
# passes through an integer value.
|
||||||
adapt_counter = self.adapt_rate*self.current_generation
|
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()
|
self.adapt()
|
||||||
|
|
||||||
number_of_generations -= 1
|
number_of_generations -= 1
|
||||||
@ -262,8 +262,11 @@ class GA(Attributes):
|
|||||||
etc.
|
etc.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if self.target_fitness_type not in ('max', 'min'):
|
||||||
|
raise ValueError("Unknown target fitness type")
|
||||||
|
|
||||||
if in_place:
|
if in_place:
|
||||||
chromosome_list.sort( # list to be sorted
|
chromosome_list.sort( # list to be sorted
|
||||||
key = lambda chromosome: chromosome.fitness, # by fitness
|
key = lambda chromosome: chromosome.fitness, # by fitness
|
||||||
reverse = (self.target_fitness_type == 'max') # ordered by fitness type
|
reverse = (self.target_fitness_type == 'max') # ordered by fitness type
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user