Skip to content

How to use On_stop function on pygad? #23

Closed Answered by ahmedfgad
itmamdiyar26 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @itmamdiyar26,

Thanks for using PyGAD!

Please note that calling the on_stop() function will not stop the algorithm. It is just a callback function that is called when the algorithm stops. In your code, calling the on_stop() function just executes its body.

All the functions that start with on_ are callback functions and are not meant to be called by the user but automatically according to flow of execution.

To stop the algorithm before passing through all the generations, then simply return the string "stop" inside the on_generation() callback function. After returning "stop", then the on_stop() function will be called automatically (in case you assigned a valid function to the on_stop

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@itmamdiyar26
Comment options

Answer selected by itmamdiyar26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants