diff --git a/Solid/GeneticAlgorithm.py b/Solid/GeneticAlgorithm.py index cf1c83c..01affd2 100644 --- a/Solid/GeneticAlgorithm.py +++ b/Solid/GeneticAlgorithm.py @@ -32,7 +32,7 @@ def __init__(self, crossover_rate, mutation_rate, max_steps, max_fitness=None): :param max_fitness: fitness value to stop algorithm once reached """ if isinstance(crossover_rate, float): - if crossover_rate >= 0 and crossover_rate <= 1: + if 0 <= crossover_rate <= 1: self.crossover_rate = crossover_rate else: raise ValueError('Crossover rate must be a float between 0 and 1') @@ -40,7 +40,7 @@ def __init__(self, crossover_rate, mutation_rate, max_steps, max_fitness=None): raise ValueError('Crossover rate must be a float between 0 and 1') if isinstance(mutation_rate, float): - if mutation_rate >= 0 and mutation_rate <= 1: + if 0 <= mutation_rate <= 1: self.mutation_rate = mutation_rate else: raise ValueError('Mutation rate must be a float between 0 and 1') @@ -186,7 +186,7 @@ def run(self, verbose=True): for i in range(self.max_steps): self.cur_steps += 1 - if ((i + 1) % 100 == 0) and verbose: + if verbose and ((i + 1) % 100 == 0): print(self) self.population = self._select_n(num_copy)