Skip to content

Commit 004dbdd

Browse files
authored
Merge pull request #1 from martiasG/feature/progressbar
Update pygad.py
2 parents 2f2c825 + e303fa6 commit 004dbdd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pygad.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pickle
55
import time
66
import warnings
7+
from tqdm.auto import tqdm
78

89
class GA:
910

@@ -91,7 +92,10 @@ def __init__(self,
9192
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.
9293
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.
9394
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.
9599
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.
96100
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.
97101
@@ -1201,7 +1205,7 @@ def run(self):
12011205
if self.save_solutions:
12021206
self.solutions.extend(self.population.copy())
12031207

1204-
for generation in range(self.num_generations):
1208+
for generation in tqdm(range(self.num_generations)):
12051209
if not (self.on_fitness is None):
12061210
self.on_fitness(self, self.last_generation_fitness)
12071211

0 commit comments

Comments
 (0)