Skip to content

Commit 4cd9c61

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 04605a0 commit 4cd9c61

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

genetic_algorithm/genetic_algorithm_optimization.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(
2525
generations: int,
2626
mutation_prob: float,
2727
crossover_rate: float,
28-
maximize: bool = True
28+
maximize: bool = True,
2929
) -> None:
3030
self.function = function # Target function to optimize
3131
self.bounds = bounds # Search space bounds (for each variable)
@@ -75,7 +75,9 @@ def fitness(self, individual: np.ndarray) -> float:
7575
value = self.function(*individual)
7676
return value if self.maximize else -value # If minimizing, invert the fitness
7777

78-
def select_parents(self, population_score: list[tuple[np.ndarray, float]]) -> list[np.ndarray]:
78+
def select_parents(
79+
self, population_score: list[tuple[np.ndarray, float]]
80+
) -> list[np.ndarray]:
7981
"""
8082
Select top N_SELECTED parents based on fitness.
8183
@@ -94,7 +96,9 @@ def select_parents(self, population_score: list[tuple[np.ndarray, float]]) -> li
9496
population_score.sort(key=lambda x: x[1], reverse=True)
9597
return [ind for ind, _ in population_score[:N_SELECTED]]
9698

97-
def crossover(self, parent1: np.ndarray, parent2: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
99+
def crossover(
100+
self, parent1: np.ndarray, parent2: np.ndarray
101+
) -> tuple[np.ndarray, np.ndarray]:
98102
"""
99103
Perform uniform crossover between two parents to generate offspring.
100104

0 commit comments

Comments
 (0)