@@ -46,7 +46,8 @@ def crossover(self, parent1: Chromosome, parent2: Chromosome):
4646 number_of_points = self .rng .integers (1 , high = number_of_genes - 1 )
4747
4848 # Select randomly the crossover points.
49- cross_points = sorted (self .rng .choice (number_of_genes , size = number_of_points ,
49+ cross_points = sorted (self .rng .choice (number_of_genes ,
50+ size = number_of_points ,
5051 replace = False , shuffle = False ))
5152
5253 # Initialize the genome of the new chromosomes to 'None'.
@@ -56,8 +57,8 @@ def crossover(self, parent1: Chromosome, parent2: Chromosome):
5657 # Copy the genes of the parents at
5758 # the preselected gene cross points.
5859 for i in cross_points :
59- genome_1 [i ] = parent2 .genome [i ]
60- genome_2 [i ] = parent1 .genome [i ]
60+ genome_1 [i ] = parent2 .genome [i ]. clone ()
61+ genome_2 [i ] = parent1 .genome [i ]. clone ()
6162 # _end_for_
6263
6364 # Fill the rest of the positions in both offsprings.
@@ -69,7 +70,7 @@ def crossover(self, parent1: Chromosome, parent2: Chromosome):
6970 j = genome_1 .index (None )
7071
7172 # Assign the current gene value.
72- genome_1 [j ] = gene1
73+ genome_1 [j ] = gene1 . clone ()
7374 # _end_if_
7475
7576 # Check if 'gene2' exists in 2nd offspring.
@@ -78,7 +79,7 @@ def crossover(self, parent1: Chromosome, parent2: Chromosome):
7879 k = genome_2 .index (None )
7980
8081 # Assign the current gene value.
81- genome_2 [k ] = gene2
82+ genome_2 [k ] = gene2 . clone ()
8283 # _end_if_
8384
8485 # _end_for_
0 commit comments