Fixed edge case for adapt_population
This commit is contained in:
@ -211,6 +211,7 @@ class GA(Attributes):
|
|||||||
|
|
||||||
# Replace worst chromosomes with new chromosomes, except for the previous best chromosome
|
# Replace worst chromosomes with new chromosomes, except for the previous best chromosome
|
||||||
min_len = min(len(self.population)-1, len(self.population.next_population))
|
min_len = min(len(self.population)-1, len(self.population.next_population))
|
||||||
|
if min_len > 0:
|
||||||
self.population[-min_len:] = self.population.next_population[:min_len]
|
self.population[-min_len:] = self.population.next_population[:min_len]
|
||||||
self.population.next_population = []
|
self.population.next_population = []
|
||||||
self.population.mating_pool = []
|
self.population.mating_pool = []
|
||||||
|
|||||||
Reference in New Issue
Block a user