Skip to content

Commit

Permalink
Update GeneticAlgorithm.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss authored Jul 6, 2017
1 parent 8ba74d3 commit 084884a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Solid/GeneticAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ 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')
else:
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')
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 084884a

Please sign in to comment.