Skip to content

Conversation

@yoonghm
Copy link

@yoonghm yoonghm commented Apr 25, 2020

By putting load() as a static function for GA, the usage of this nice library could be more concise

from pygad import GA

def fitness_func(solution):
    return fitness_value

ga = GA(
    # ...
)

ga.run()
ga.plot_result()
best_solution, best_solution_fitness = ga.best_solution()
print(f'Best solution:, {best_solution}')
print(f'Fitness value of the best solution: {best_solution_fitness}')
ga.save(filename)

By putting `load()` as a static function for `GA`, the usage of this nice library could be more concise

```Python
from pygad import GA

def fitness_func(solution):
    return fitness_value

ga = GA(
    # ...
)

ga.run()
ga.plot_result()
best_solution, best_solution_fitness = ga.best_solution()
print(f'Best solution:, {best_solution}')
print(f'Fitness value of the best solution: {best_solution_fitness}')
ga.save(filename)
```
@ahmedfgad
Copy link
Owner

The load() function is added inside the pygad module outside the GA class which means it is not related at all to the instance.

You just moved the function to be indented behind the GA class and added the @staticmethod decorator to achieve the purpose fulfilled by just placing it outside the GA class.

Either way, the primary goal is achieved.

@ahmedfgad ahmedfgad self-assigned this May 4, 2020
@ahmedfgad ahmedfgad added the enhancement New feature or request label May 4, 2020
@ahmedfgad ahmedfgad closed this May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants