File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff 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
202206def mutation (genome : genome_t , p_mutation : float ) -> genome_t :
You can’t perform that action at this time.
0 commit comments