godatadriven / evol

a python grammar for evolutionary algorithms and heuristics
https://evol.rtfd.io
MIT License
187 stars 12 forks source link

Not sure if elitism works #163

Closed Alfie8362 closed 2 years ago

Alfie8362 commented 2 years ago

I put elitist to True in my mutation step, but it did not work when looking at the source code it looks like it will not work.

elite_fitness = self.current_best if elitist else None for individual in self.individuals: if elite_fitness is None or individual.fitness != elite_fitness: individual.mutate(mutate_function, probability=probability, **kwargs) return self

elite_fitness is set as an 'individual' object, then in the if statement it is compared to the floating point fitness instead of the actual object. Therefore individual.fitness will never equal elite_fitness and the current_best is not skipped over like it should be.

rogiervandergeer commented 2 years ago

Good catch! #164 should fix it.