Skip to content

Commit

Permalink
Stopping the evaluation as soon as the one max individual is found
Browse files Browse the repository at this point in the history
Considering the task at hand I do not really get why the evolution
should be run for a fixed number of iterations. It would be more
plausible, in my opinion, to terminate the evaluation as soon as the
desired individual, the one containing only 1, is found.
  • Loading branch information
theGreatWhiteShark committed Apr 20, 2017
1 parent 80f7cdb commit 875d918
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions examples/ga/onemax.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ def main():
# are crossed
#
# MUTPB is the probability for mutating an individual
#
# NGEN is the number of generations for which the
# evolution runs
CXPB, MUTPB, NGEN = 0.5, 0.2, 40
CXPB, MUTPB = 0.5, 0.2

print("Start of evolution")

Expand All @@ -93,9 +90,17 @@ def main():
ind.fitness.values = fit

print(" Evaluated %i individuals" % len(pop))

# Extracting all the fitnesses of
fits = [ind.fitness.values[0] for ind in pop]

# Variable keeping track of the number of generations
g = 0

# Begin the evolution
for g in range(NGEN):
while max(fits) < 100:
# A new generation
g = g + 1
print("-- Generation %i --" % g)

# Select the next generation individuals
Expand Down

0 comments on commit 875d918

Please sign in to comment.