Skip to content

Commit 21bcad9

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 7b85f11 commit 21bcad9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

genetic_algorithm/genetic_algorithm_optimization.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# Random number generator
1414
rng = np.random.default_rng()
1515

16+
1617
class GeneticAlgorithm:
1718
def __init__(
1819
self,
@@ -72,7 +73,9 @@ def mutate(self, individual):
7273
def evaluate_population(self):
7374
# Multithreaded evaluation of population fitness
7475
with ThreadPoolExecutor() as executor:
75-
return list(executor.map(lambda ind: (ind, self.fitness(ind)), self.population))
76+
return list(
77+
executor.map(lambda ind: (ind, self.fitness(ind)), self.population)
78+
)
7679

7780
def evolve(self):
7881
for generation in range(self.generations):
@@ -95,7 +98,7 @@ def evolve(self):
9598
next_generation.append(self.mutate(child2))
9699

97100
# Ensure population size remains the same
98-
self.population = next_generation[:self.population_size]
101+
self.population = next_generation[: self.population_size]
99102

100103
if generation % 10 == 0:
101104
print(f"Generation {generation}: Best Fitness = {best_fitness}")
@@ -119,7 +122,7 @@ def target_function(x, y):
119122
generations=N_GENERATIONS,
120123
mutation_prob=MUTATION_PROBABILITY,
121124
crossover_rate=CROSSOVER_RATE,
122-
maximize=False # Minimize the function
125+
maximize=False, # Minimize the function
123126
)
124127

125128
best_solution = ga.evolve()

0 commit comments

Comments
 (0)