Skip to content

Commit f65305a

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 2cfc1bc commit f65305a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

genetic_algorithm/knapsack.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ def random_genome(length: int) -> genome_t:
142142
return [random.randint(0, 1) for _ in range(length)]
143143

144144

145-
def selection(population: list[genome_t], fitnesses: list[int], tournament_k: int) -> genome_t:
145+
def selection(
146+
population: list[genome_t], fitnesses: list[int], tournament_k: int
147+
) -> genome_t:
146148
"""
147149
Performs tournament selection to choose a genome from the population.
148150
@@ -196,7 +198,9 @@ def crossover(
196198
if random.random() > p_crossover or min_length < 2:
197199
return genome_1[:], genome_2[:]
198200
cutoff_point = random.randint(1, min_length - 1)
199-
return genome_1[:cutoff_point] + genome_2[cutoff_point:], genome_2[:cutoff_point] + genome_1[cutoff_point:]
201+
return genome_1[:cutoff_point] + genome_2[cutoff_point:], genome_2[
202+
:cutoff_point
203+
] + genome_1[cutoff_point:]
200204

201205

202206
def mutation(genome: genome_t, p_mutation: float) -> genome_t:

0 commit comments

Comments
 (0)