GeneticAlgorithmPython icon indicating copy to clipboard operation
GeneticAlgorithmPython copied to clipboard

Add parameter count adjustment for functions that are class methods

Open richmr opened this issue 3 years ago • 0 comments

Hi, I am using PyGAD.GA inside of another class. The various functions PyGAD will accept as parameters have strict parameter count checks. However, when you assign a class method to these functions they get an extra "self" parameter assigned to them. PyGAD then interprets these extra self parameters as improperly constructed functions.

Using the "inspect" module I have added a check to see if an assigned function is actually a method. If so, it then adds one to the expected parameter count. This allows these methods to be used as contributing functions. This, in turn, permits more well-formatted object oriented code to be used when desired. Users can still assign non-class functions to these parameters and the code will accept them.

I am using this in my current experiments and it is working well.

Thanks for your time!

Mike

richmr avatar Mar 09 '22 04:03 richmr