Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verbose mode #6

Merged
merged 1 commit into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ Advanced
crossover_probability=0.8,
mutation_probability=0.05,
elitism=True,
maximise_fitness=True)
maximise_fitness=True,
verbose=False)


Or ::
Expand Down
6 changes: 5 additions & 1 deletion pyeasyga/pyeasyga.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def __init__(self,
crossover_probability=0.8,
mutation_probability=0.2,
elitism=True,
maximise_fitness=True):
maximise_fitness=True,
verbose=False):
"""Instantiate the Genetic Algorithm.

:param seed_data: input data to the Genetic Algorithm
Expand All @@ -59,6 +60,7 @@ def __init__(self,
self.mutation_probability = mutation_probability
self.elitism = elitism
self.maximise_fitness = maximise_fitness
self.verbose = verbose

self.current_generation = []

Expand Down Expand Up @@ -193,6 +195,8 @@ def create_next_generation(self):
self.create_new_population()
self.calculate_population_fitness()
self.rank_population()
if self.verbose:
print("Fitness: %f" % self.best_individual()[0])

def run(self):
"""Run (solve) the Genetic Algorithm."""
Expand Down