Skip to content

Commit ba55f17

Browse files
committed
Force not allow_duplicate_genes to work
1 parent 2510727 commit ba55f17

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pygad.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,7 @@ def single_point_crossover(self, parents, offspring_size):
16951695
# The new offspring has its second half of its genes from the second parent.
16961696
offspring[k, crossover_point:] = parents[parent2_idx, crossover_point:]
16971697

1698-
if (self.mutation_type is None) and (self.allow_duplicate_genes == False):
1698+
if self.allow_duplicate_genes == False:
16991699
if self.gene_space is None:
17001700
offspring[k], _, _ = self.solve_duplicate_genes_randomly(solution=offspring[k],
17011701
min_val=self.random_mutation_min_val,
@@ -1761,7 +1761,7 @@ def two_points_crossover(self, parents, offspring_size):
17611761
# The genes between the 2 points are copied from the second parent.
17621762
offspring[k, crossover_point1:crossover_point2] = parents[parent2_idx, crossover_point1:crossover_point2]
17631763

1764-
if (self.mutation_type is None) and (self.allow_duplicate_genes == False):
1764+
if self.allow_duplicate_genes == False:
17651765
if self.gene_space is None:
17661766
offspring[k], _, _ = self.solve_duplicate_genes_randomly(solution=offspring[k],
17671767
min_val=self.random_mutation_min_val,
@@ -1821,7 +1821,7 @@ def uniform_crossover(self, parents, offspring_size):
18211821
# The gene will be copied from the second parent if the current gene index is 1.
18221822
offspring[k, gene_idx] = parents[parent2_idx, gene_idx]
18231823

1824-
if (self.mutation_type is None) and (self.allow_duplicate_genes == False):
1824+
if self.allow_duplicate_genes == False:
18251825
if self.gene_space is None:
18261826
offspring[k], _, _ = self.solve_duplicate_genes_randomly(solution=offspring[k],
18271827
min_val=self.random_mutation_min_val,
@@ -1877,7 +1877,7 @@ def scattered_crossover(self, parents, offspring_size):
18771877
gene_sources = numpy.random.randint(0, 2, size=self.num_genes)
18781878
offspring[k, :] = numpy.where(gene_sources == 0, parents[parent1_idx, :], parents[parent2_idx, :])
18791879

1880-
if (self.mutation_type is None) and (self.allow_duplicate_genes == False):
1880+
if self.allow_duplicate_genes == False:
18811881
if self.gene_space is None:
18821882
offspring[k], _, _ = self.solve_duplicate_genes_randomly(solution=offspring[k],
18831883
min_val=self.random_mutation_min_val,

0 commit comments

Comments
 (0)