You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. The `best_solution()` method in the `pygad.GA` class returns a new output representing the index of the best solution within the population. Now, it returns a total of 3 outputs and their order is: best solution, best solution fitness, and best solution idx. Here is an example:
```python
solution, solution_fitness, solution_idx = ga_instance.best_solution()
print("Parameters of the best solution :", solution)
print("Fitness value of the best solution :", solution_fitness, "\n")
print("Index of the best solution :", solution_idx, "\n")
2. A new attribute named `best_solution_generation` is added to the instances of the pygad.GA class. it holds the generation number at which the best solution is reached. It is only assigned the generation number after the `run()` method completes. Otherwise, its value is -1.
Example:
```python
print("Best solution reached after {best_solution_generation} generations.".format(best_solution_generation=ga_instance.best_solution_generation))
# Even such this parameter is declared in the class header, it is assigned to the object here to access it after saving the object.
232
-
self.best_solution_fitness= [] # A list holding the fitness value of the best solution for each generation.
232
+
self.best_solutions_fitness= [] # A list holding the fitness value of the best solution for each generation.
233
+
234
+
self.best_solution_generation=-1# The generation number at which the best solution is reached. It is only assigned the generation number after the `run()` method completes. Otherwise, its value is -1.
# print("Warning calling the plot_result() method: \nGA is not executed yet and there are no results to display. Please call the run() method before calling the plot_result() method.\n")
0 commit comments