8000 Update Example_GeneticAlgorithm.py · ahmedfiz/GeneticAlgorithmPython@9b9166a · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b9166a

Browse files
authored
Update Example_GeneticAlgorithm.py
1 parent 647c700 commit 9b9166a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Example_GeneticAlgorithm.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
fitness = GA.cal_pop_fitness(equation_inputs, new_population)
4747
print("Fitness")
4848
print(fitness)
49+
50+
best_outputs.append(numpy.max(numpy.sum(new_population*equation_inputs, axis=1)))
51+
# The best result in the current iteration.
52+
print("Best result : ", numpy.max(numpy.sum(new_population*equation_inputs, axis=1)))
53+
4954
# Selecting the best parents in the population for mating.
5055
parents = GA.select_mating_pool(new_population, fitness,
5156
num_parents_mating)
@@ -58,7 +63,7 @@
5863
print("Crossover")
5964
print(offspring_crossover)
6065

61-
# Adding some variations to the offsrping using mutation.
66+
# Adding some variations to the offspring using mutation.
6267
offspring_mutation = GA.mutation(offspring_crossover)
6368
print("Mutation")
6469
print(offspring_mutation)
@@ -67,10 +72,6 @@
6772
new_population[0:parents.shape[0], :] = parents
6873
new_population[parents.shape[0]:, :] = offspring_mutation
6974

70-
best_outputs.append(numpy.max(numpy.sum(new_population*equation_inputs, axis=1)))
71-
# The best result in the current iteration.
72-
print("Best result : ", numpy.max(numpy.sum(new_population*equation_inputs, axis=1)))
73-
7475
# Getting the best solution after iterating finishing all generations.
7576
#At first, the fitness is calculated for each solution in the final generation.
7677
fitness = GA.cal_pop_fitness(equation_inputs, new_population)

0 commit comments

Comments
 (0)
0