-
-
Notifications
You must be signed in to change notification settings - Fork 335
/
FitnessBasedReinsertion.cs
45 lines (42 loc) · 1.67 KB
/
FitnessBasedReinsertion.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
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace GeneticSharp
{
/// <summary>
/// Fitness Based Reinsertion.
/// <remarks>
/// When there are more offspring than parents, select the only the best offspring to be reinserted, the parents are discarded.
/// <see href="http://usb-bg.org/Bg/Annual_Informatics/2011/SUB-Informatics-2011-4-29-35.pdf">Generalized Nets Model of offspring Reinsertion in Genetic Algorithm</see>
/// </remarks>
/// </summary>
[DisplayName("Fitness Based")]
public class FitnessBasedReinsertion : ReinsertionBase
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="GeneticSharp.FitnessBasedReinsertion"/> class.
/// </summary>
public FitnessBasedReinsertion() : base(true, false)
{
}
#endregion
#region Methods
/// <summary>
/// Selects the chromosomes which will be reinserted.
/// </summary>
/// <returns>The chromosomes to be reinserted in next generation..</returns>
/// <param name="population">The population.</param>
/// <param name="offspring">The offspring.</param>
/// <param name="parents">The parents.</param>
protected override IList<IChromosome> PerformSelectChromosomes(IPopulation population, IList<IChromosome> offspring, IList<IChromosome> parents)
{
if (offspring.Count > population.MaxSize)
{
return offspring.OrderByDescending(o => o.Fitness).Take(population.MaxSize).ToList();
}
return offspring;
}
#endregion
}
}