diff --git a/pygad.py b/pygad.py index 4b1e2916..071658a2 100644 --- a/pygad.py +++ b/pygad.py @@ -1695,7 +1695,7 @@ def single_point_crossover(self, parents, offspring_size): # The new offspring has its second half of its genes from the second parent. offspring[k, crossover_point:] = parents[parent2_idx, crossover_point:] - if (self.mutation_type is None) and (self.allow_duplicate_genes == False): + if self.allow_duplicate_genes == False: if self.gene_space is None: offspring[k], _, _ = self.solve_duplicate_genes_randomly(solution=offspring[k], min_val=self.random_mutation_min_val, @@ -1761,7 +1761,7 @@ def two_points_crossover(self, parents, offspring_size): # The genes between the 2 points are copied from the second parent. offspring[k, crossover_point1:crossover_point2] = parents[parent2_idx, crossover_point1:crossover_point2] - if (self.mutation_type is None) and (self.allow_duplicate_genes == False): + if self.allow_duplicate_genes == False: if self.gene_space is None: offspring[k], _, _ = self.solve_duplicate_genes_randomly(solution=offspring[k], min_val=self.random_mutation_min_val, @@ -1821,7 +1821,7 @@ def uniform_crossover(self, parents, offspring_size): # The gene will be copied from the second parent if the current gene index is 1. offspring[k, gene_idx] = parents[parent2_idx, gene_idx] - if (self.mutation_type is None) and (self.allow_duplicate_genes == False): + if self.allow_duplicate_genes == False: if self.gene_space is None: offspring[k], _, _ = self.solve_duplicate_genes_randomly(solution=offspring[k], min_val=self.random_mutation_min_val, @@ -1877,7 +1877,7 @@ def scattered_crossover(self, parents, offspring_size): gene_sources = numpy.random.randint(0, 2, size=self.num_genes) offspring[k, :] = numpy.where(gene_sources == 0, parents[parent1_idx, :], parents[parent2_idx, :]) - if (self.mutation_type is None) and (self.allow_duplicate_genes == False): + if self.allow_duplicate_genes == False: if self.gene_space is None: offspring[k], _, _ = self.solve_duplicate_genes_randomly(solution=offspring[k], min_val=self.random_mutation_min_val, @@ -3361,7 +3361,8 @@ def plot_fitness(self, font_size=14, plot_type="plot", color="#3870FF", - save_dir=None): + save_dir=None, + show=True): """ Creates, shows, and returns a figure that summarizes how the fitness value evolved by generation. Can only be called after completing at least 1 generation. If no generation is completed, an exception is raised. @@ -3375,7 +3376,7 @@ def plot_fitness(self, plot_type: Type of the plot which can be either "plot" (default), "scatter", or "bar". color: Color of the plot which defaults to "#3870FF". save_dir: Directory to save the figure. - + show: For True show the plot Returns the figure. """ @@ -3399,7 +3400,8 @@ def plot_fitness(self, if not save_dir is None: matplotlib.pyplot.savefig(fname=save_dir, bbox_inches='tight') - matplotlib.pyplot.show() + if show: + matplotlib.pyplot.show() return fig