Skip to content

Refactor the pygad.py script#345

Merged
ahmedfgad merged 3 commits intomasterfrom
github-actions
Mar 30, 2026
Merged

Refactor the pygad.py script#345
ahmedfgad merged 3 commits intomasterfrom
github-actions

Conversation

@ahmedfgad
Copy link
Copy Markdown
Owner

These are just some of the changes in the upcoming PyGAD 3.6.0 release. Except for the first change, it is about refactoring the pygad.py script to move the code into different scripts instead of having a single large file.

  1. Support passing a class to the fitness, crossover, and mutation. Accepting classes with __call__ methods implemented, not only functions #342
  2. A new class called Validation is created in the new pygad/utils/validation.py script. It has a method called validate_parameters() to validate all the parameters passed while instantiating the pygad.GA class.
  3. Refactoring the pygad.py script by moving a lot of functions and methods to other classes in other scripts.
    1. The summary() method was moved to Helper class in the pygad/helper/misc.py script.
    2. The validation code in the __init__() method of the pygad.GA class is moved to the new validate_parameters() method in the new Validation class in the new pygad/utils/validation.py script. Moreover, the validate_multi_stop_criteria() method is also moved to the same class.
    3. The GA main workflow is moved into the new GAEngine class in the new pygad/utils/engine.py script. Specifically, these methods are moved from the pygad.GA class to the new GAEngine class:
      1. run()
      2. run_loop_head()
      3. run_select_parents()
      4. run_crossover()
      5. run_mutation()
      6. run_update_population()
      7. initialize_population()
      8. cal_pop_fitness()
      9. best_solution()
      10. round_genes()
  4. The pygad.GA class now extends the two new classes utils.validation.Validation and utils.engine.GAEngine.
  5. The version of the pygad.utils submodule is upgraded from 1.3.0 to 1.4.0.
  6. The version of the pygad.helper submodule is upgraded from 1.2.0 to 1.3.0.

@ahmedfgad ahmedfgad merged commit 8c1d6ff into master Mar 30, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant