forked from andrewkirillov/AForge.NET
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathEliteSelection.cs
48 lines (44 loc) · 1.39 KB
/
EliteSelection.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
// AForge Genetic Library
// AForge.NET framework
// http://www.aforgenet.com/framework/
//
// Copyright © Andrew Kirillov, 2006-2009
// andrew.kirillov@aforgenet.com
//
namespace AForge.Genetic
{
using System;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Elite selection method.
/// </summary>
///
/// <remarks>Elite selection method selects specified amount of
/// best chromosomes to the next generation.</remarks>
///
public class EliteSelection : ISelectionMethod
{
/// <summary>
/// Initializes a new instance of the <see cref="EliteSelection"/> class.
/// </summary>
public EliteSelection( ) { }
/// <summary>
/// Apply selection to the specified population.
/// </summary>
///
/// <param name="chromosomes">Population, which should be filtered.</param>
/// <param name="size">The amount of chromosomes to keep.</param>
///
/// <remarks>Filters specified population keeping only specified amount of best
/// chromosomes.</remarks>
///
public void ApplySelection( List<IChromosome> chromosomes, int size )
{
// sort chromosomes
chromosomes.Sort( );
// remove bad chromosomes
chromosomes.RemoveRange( size, chromosomes.Count - size );
}
}
}