GeneticAlgorithmPython icon indicating copy to clipboard operation
GeneticAlgorithmPython copied to clipboard

Calling some function before fitness_func in adaptive mutation

Open hmcezar opened this issue 1 year ago • 1 comments

During the adaptive mutation, the fitness function is called in https://github.com/ahmedfgad/GeneticAlgorithmPython/blob/0e8be9d61070df832ab89cae993e8827567d1184/pygad/utils/mutation.py#L473

In my application, this is a problem because I have to normalize some optimized probabilities before computing the fitness. So if I have g1, g2, g3, g4 as genes that are optimized with the GA, and I need sum(g1, g2, g3, g4) = 1 for my fitness function, I most likely get an error.

The way I'm doing things with random mutation is that I normalize this in my on_mutation method. Is there a way of using adaptive mutation with such restrictions?

hmcezar avatar Aug 12 '24 14:08 hmcezar

Unfortunately adding restrictions over all the genes is not possible at the moment. Restrictions are set at the gene level.

ahmedfgad avatar Jan 07 '25 19:01 ahmedfgad