@@ -937,19 +937,19 @@ def run(self):
937
937
# Measuring the fitness of each chromosome in the population. Save the fitness in the last_generation_fitness attribute.
938
938
self .last_generation_fitness = self .cal_pop_fitness ()
939
939
940
+ best_solution , best_solution_fitness , best_match_idx = self .best_solution (pop_fitness = self .last_generation_fitness )
941
+
942
+ # Appending the best solution in the initial population to the best_solutions list.
943
+ if self .save_best_solutions :
944
+ self .best_solutions .append (best_solution )
945
+
940
946
for generation in range (self .num_generations ):
941
947
if not (self .on_fitness is None ):
942
948
self .on_fitness (self , self .last_generation_fitness )
943
949
944
- best_solution , best_solution_fitness , best_match_idx = self .best_solution (pop_fitness = self .last_generation_fitness )
945
-
946
950
# Appending the fitness value of the best solution in the current generation to the best_solutions_fitness attribute.
947
951
self .best_solutions_fitness .append (best_solution_fitness )
948
952
949
- # Appending the best solution to the best_solutions list.
950
- if self .save_best_solutions :
951
- self .best_solutions .append (best_solution )
952
-
953
953
# Selecting the best parents in the population for mating.
954
954
self .last_generation_parents = self .select_parents (self .last_generation_fitness , num_parents = self .num_parents_mating )
955
955
if not (self .on_parents is None ):
@@ -993,6 +993,12 @@ def run(self):
993
993
# Measuring the fitness of each chromosome in the population. Save the fitness in the last_generation_fitness attribute.
994
994
self .last_generation_fitness = self .cal_pop_fitness ()
995
995
996
+ best_solution , best_solution_fitness , best_match_idx = self .best_solution (pop_fitness = self .last_generation_fitness )
997
+
998
+ # Appending the best solution to the best_solutions list.
999
+ if self .save_best_solutions :
1000
+ self .best_solutions .append (best_solution )
1001
+
996
1002
# If the callback_generation attribute is not None, then cal the callback function after the generation.
997
1003
if not (self .on_generation is None ):
998
1004
r = self .on_generation (self )
0 commit comments