GeneticSharp
GeneticSharp copied to clipboard
Selection doesn't seem to do anything
Describe the bug It seems that Selection has no effect on population?
To Reproduce
- Replace
GeneticAlghoritm.SelectParentswith 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;
}
- Run any provided example.
- Code inside
ifstatement 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
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?
Closed due to inactivity. Feel free to reopen it if needed.