giacomelli / GeneticSharp

GeneticSharp is a fast, extensible, multi-platform and multithreading C# Genetic Algorithm library that simplifies the development of applications using Genetic Algorithms (GAs).
MIT License
1.26k stars 330 forks source link

FitnessStagnationTermination Does Not Terminate at Expected Generation When Using GenerationRan Event #118

Closed DavidLC98 closed 8 months ago

DavidLC98 commented 8 months ago

Issue Summary: When using FitnessStagnationTermination with a specific generation limit (1000 in this case), the genetic algorithm does not terminate at the expected generation. Instead, it continues running, often concluding around the 2000th generation.

Steps to Reproduce: 1- Set up the termination condition of a Genetic Algorithm (GA) using FitnessStagnationTermination, like so: var termination = new FitnessStagnationTermination(1000);

2- Subscribe to the GA's GenerationRan event to perform an action in each generation (e.g., updating a progress bar): ga.GenerationRan += Ga_GenerationRan;

3- Run the GA.

Expected Behavior: The GA process should terminate upon reaching 1000 generations as specified in the FitnessStagnationTermination setting.

Actual Behavior: The GA process does not terminate at the 1000th generation as expected. It often continues running until approximately the 2000th generation.

My real Code: image

giacomelli commented 8 months ago

From your description, it sounds like you want GenerationNumberTermination instead of FitnessStagnationTermination.

Read more about Terminations on this wiki page: https://github.com/giacomelli/GeneticSharp/wiki/terminations