|
46 | 46 | fitness = GA.cal_pop_fitness(equation_inputs, new_population) |
47 | 47 | print("Fitness") |
48 | 48 | 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 | + |
49 | 54 | # Selecting the best parents in the population for mating. |
50 | 55 | parents = GA.select_mating_pool(new_population, fitness, |
51 | 56 | num_parents_mating) |
|
58 | 63 | print("Crossover") |
59 | 64 | print(offspring_crossover) |
60 | 65 |
|
61 | | - # Adding some variations to the offsrping using mutation. |
| 66 | + # Adding some variations to the offspring using mutation. |
62 | 67 | offspring_mutation = GA.mutation(offspring_crossover) |
63 | 68 | print("Mutation") |
64 | 69 | print(offspring_mutation) |
|
67 | 72 | new_population[0:parents.shape[0], :] = parents |
68 | 73 | new_population[parents.shape[0]:, :] = offspring_mutation |
69 | 74 |
|
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 | | - |
74 | 75 | # Getting the best solution after iterating finishing all generations. |
75 | 76 | #At first, the fitness is calculated for each solution in the final generation. |
76 | 77 | fitness = GA.cal_pop_fitness(equation_inputs, new_population) |
|
0 commit comments