forked from giacomelli/GeneticSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelectionBase.cs
58 lines (52 loc) · 2.24 KB
/
SelectionBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using GeneticSharp.Domain.Chromosomes;
using GeneticSharp.Domain.Populations;
using GeneticSharp.Infrastructure.Framework.Texts;
using GeneticSharp.Infrastructure.Framework.Commons;
namespace GeneticSharp.Domain.Selections
{
/// <summary>
/// A base class for selection.
/// </summary>
public abstract class SelectionBase : ISelection
{
#region Fields
private int m_minNumberChromosomes;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="GeneticSharp.Domain.Selections.SelectionBase"/> class.
/// </summary>
/// <param name="minNumberChromosomes">Minimum number chromosomes support to be selected.</param>
protected SelectionBase(int minNumberChromosomes)
{
m_minNumberChromosomes = minNumberChromosomes;
}
#endregion
#region ISelection implementation
/// <summary>
/// Selects the number of chromosomes from the generation specified.
/// </summary>
/// <returns>The selected chromosomes.</returns>
/// <param name="number">The number of chromosomes to select.</param>
/// <param name="generation">The generation where the selection will be made.</param>
public IList<IChromosome> SelectChromosomes(int number, Generation generation)
{
if (number < m_minNumberChromosomes)
{
throw new ArgumentOutOfRangeException("number", "The number of selected chromosomes should be at least {0}.".With(m_minNumberChromosomes));
}
ExceptionHelper.ThrowIfNull("generation", generation);
return PerformSelectChromosomes(number, generation);
}
/// <summary>
/// Performs the selection of chromosomes from the generation specified.
/// </summary>
/// <returns>The selected chromosomes.</returns>
/// <param name="number">The number of chromosomes to select.</param>
/// <param name="generation">The generation where the selection will be made.</param>
protected abstract IList<IChromosome> PerformSelectChromosomes(int number, Generation generation);
#endregion
}
}