GeneticSharp icon indicating copy to clipboard operation
GeneticSharp copied to clipboard

Selection doesn't seem to do anything

Open dex3r opened this issue 4 years ago • 1 comments
trafficstars

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;
}
  1. Run any provided example.
  2. 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

dex3r avatar Feb 28 '21 19:02 dex3r

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 avatar Sep 08 '22 08:09 giacomelli

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

giacomelli avatar Nov 23 '22 18:11 giacomelli