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

Selection doesn't seem to do anything #91

Closed dex3r closed 1 year ago

dex3r commented 3 years ago

Describe the bug It seems that Selection has no effect on population?

To Reproduce

  1. Replace GeneticAlghoritm.SelectParents with this code:

    private IList<IChromosome> SelectParents()
    {
    int beforeSelectionCount = Population.CurrentGeneration.Chromosomes.Count;
    
    IList<IChromosome> parents = Selection.SelectChromosomes(Population.MinSize, Population.CurrentGeneration);
    
    int afterCount = parents.Count;
    if(beforeSelectionCount != afterCount)
    {
        Debug.WriteLine($"Prev != after! Prev: {beforeSelectionCount} after: {afterCount}");
    }
    
    return parents;
    }
  2. Run any provided example.
  3. Code inside if statement is never executed.

Expected behavior Selection should select chromosomes according to its algorithm. Instead, the population count is always equal to MinSize when entering SelectParents method, rendering any Selection method useless.

Version: Commit hash: a648e253d977ecd7afb26824141281fb9ec74ae3

giacomelli commented 1 year ago

Unfortunately, I couldn't understand what is the problem you are trying to point out in this issue, because the idea to pass MinSize to the implementation of the ISelection interface is to guarantee that the minimum size of the population will be respected, in some cases the selection could generate more chromosomes than min size, but never less than it.

Can you provide a unit test exposing the problem that you mentioned?

giacomelli commented 1 year ago

Closed due to inactivity. Feel free to reopen it if needed.