forked from giacomelli/GeneticSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PerformanceGenerationStrategy.cs
59 lines (54 loc) · 2.1 KB
/
PerformanceGenerationStrategy.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
59
using System.ComponentModel;
using GeneticSharp.Infrastructure.Framework.Commons;
namespace GeneticSharp.Domain.Populations
{
/// <summary>
/// An IGenerationStrategy's implementation which takes into account the performance and just keep the last one generations in the population.
/// <remarks>
/// This strategy is not good for tracking all the generations, for this case use TrackingGenerationStrategy,
/// but is the best one when you have a very long term termination.
/// </remarks>
/// </summary>
[DisplayName("Performance")]
public class PerformanceGenerationStrategy : IGenerationStrategy
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="PerformanceGenerationStrategy"/> class.
/// </summary>
public PerformanceGenerationStrategy()
{
GenerationsNumber = 1;
}
/// <summary>
/// Initializes a new instance of the <see cref="PerformanceGenerationStrategy"/> class.
/// </summary>
/// <param name="generationsNumber">The number of generations to keep in the population</param>
public PerformanceGenerationStrategy(int generationsNumber)
{
GenerationsNumber = generationsNumber;
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the number of generations to keep in the population.
/// <remars>The default is 1.</remars>
/// </summary>
public int GenerationsNumber { get; set; }
#endregion
#region Methods
/// <summary>
/// Register that a new generation has been created.
/// </summary>
/// <param name="population">The population where the new generation has been created.</param>
public void RegisterNewGeneration(IPopulation population)
{
ExceptionHelper.ThrowIfNull("population", population);
if (population.Generations.Count > GenerationsNumber)
{
population.Generations.RemoveAt(0);
}
}
#endregion
}
}