|
4 | 4 | import pickle |
5 | 5 | import time |
6 | 6 | import warnings |
| 7 | +from tqdm.auto import tqdm |
7 | 8 |
|
8 | 9 | class GA: |
9 | 10 |
|
@@ -91,7 +92,10 @@ def __init__(self, |
91 | 92 | on_parents: Accepts a function to be called after selecting the parents that mates. This function must accept 2 parameters: the first one represents the instance of the genetic algorithm and the second one represents the selected parents. Added in PyGAD 2.6.0. |
92 | 93 | on_crossover: Accepts a function to be called each time the crossover operation is applied. This function must accept 2 parameters: the first one represents the instance of the genetic algorithm and the second one represents the offspring generated using crossover. Added in PyGAD 2.6.0. |
93 | 94 | on_mutation: Accepts a function to be called each time the mutation operation is applied. This function must accept 2 parameters: the first one represents the instance of the genetic algorithm and the second one represents the offspring after applying the mutation. Added in PyGAD 2.6.0. |
94 | | - callback_generation: Accepts a function to be called after each generation. This function must accept a single parameter representing the instance of the genetic algorithm. If the function returned "stop", then the run() method stops without completing the other generations. Starting from PyGAD 2.6.0, the callback_generation parameter is deprecated and should be replaced by the on_generation parameter. |
| 95 | + callback_generation: Accepts a function to be called after each generation. This function must accept a single parameter representing the instance of the genetic algorithm. If the function returned "stop", then the |
| 96 | + |
| 97 | + |
| 98 | + () method stops without completing the other generations. Starting from PyGAD 2.6.0, the callback_generation parameter is deprecated and should be replaced by the on_generation parameter. |
95 | 99 | on_generation: Accepts a function to be called after each generation. This function must accept a single parameter representing the instance of the genetic algorithm. If the function returned "stop", then the run() method stops without completing the other generations. Added in PyGAD 2.6.0. |
96 | 100 | on_stop: Accepts a function to be called only once exactly before the genetic algorithm stops or when it completes all the generations. This function must accept 2 parameters: the first one represents the instance of the genetic algorithm and the second one is a list of fitness values of the last population's solutions. Added in PyGAD 2.6.0. |
97 | 101 |
|
@@ -1201,7 +1205,7 @@ def run(self): |
1201 | 1205 | if self.save_solutions: |
1202 | 1206 | self.solutions.extend(self.population.copy()) |
1203 | 1207 |
|
1204 | | - for generation in range(self.num_generations): |
| 1208 | + for generation in tqdm(range(self.num_generations)): |
1205 | 1209 | if not (self.on_fitness is None): |
1206 | 1210 | self.on_fitness(self, self.last_generation_fitness) |
1207 | 1211 |
|
|
0 commit comments