By default, PyGAD uses elitism to preserve the best solutions from one generation to the next. The keep_elitism parameter (defaulting to 1) defines how many of the best solutions from generation X are copied directly into generation X+1 at the beginning of the population (indices 0, 1, etc.).
Because these solutions are copied without changes, PyGAD reuses their previously calculated fitness values instead of calling the fitness_func again. This is why you might notice that the fitness function is not called for the solution at index 0.
To force PyGAD to call the fitness function for every single solution in every generation, you must configure the following:
- Set
keep_elitism=0 - Set
keep_parents=0 - Set
save_solutions=False - Set
save_best_solutions=False
ga_instance = pygad.GA(...,
keep_elitism=0,
keep_parents=0,
save_solutions=False,
save_best_solutions=False,
...)