mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-25 10:28:39 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
84b29c0eed
commit
9049228ff8
@ -251,7 +251,9 @@ class GeneticAlgorithm:
|
|||||||
raise ValueError("Population score is empty. No individuals evaluated.")
|
raise ValueError("Population score is empty. No individuals evaluated.")
|
||||||
|
|
||||||
# Check the best individual
|
# Check the best individual
|
||||||
best_individual = max(population_score, key=lambda score_tuple: score_tuple[1])[0]
|
best_individual = max(
|
||||||
|
population_score, key=lambda score_tuple: score_tuple[1]
|
||||||
|
)[0]
|
||||||
best_fitness = self.fitness(best_individual)
|
best_fitness = self.fitness(best_individual)
|
||||||
|
|
||||||
# Select parents for next generation
|
# Select parents for next generation
|
||||||
@ -260,7 +262,10 @@ class GeneticAlgorithm:
|
|||||||
|
|
||||||
# Generate offspring using crossover and mutation
|
# Generate offspring using crossover and mutation
|
||||||
for i in range(0, len(parents), 2):
|
for i in range(0, len(parents), 2):
|
||||||
parent1, parent2 = parents[i], parents[(i + 1) % len(parents)] # Wrap around for odd cases
|
parent1, parent2 = (
|
||||||
|
parents[i],
|
||||||
|
parents[(i + 1) % len(parents)],
|
||||||
|
) # Wrap around for odd cases
|
||||||
child1, child2 = self.crossover(parent1, parent2)
|
child1, child2 = self.crossover(parent1, parent2)
|
||||||
next_generation.append(self.mutate(child1))
|
next_generation.append(self.mutate(child1))
|
||||||
next_generation.append(self.mutate(child2))
|
next_generation.append(self.mutate(child2))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user