forked from giacomelli/GeneticSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerationNumberTermination.cs
55 lines (51 loc) · 2.02 KB
/
GenerationNumberTermination.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
using System.ComponentModel;
namespace GeneticSharp
{
/// <summary>
/// Generation number termination.
/// <remarks>
/// The genetic algorithm will be terminate when reach the expected generation number.
/// </remarks>
/// </summary>
[DisplayName("Generation Number")]
public class GenerationNumberTermination : TerminationBase
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="GeneticSharp.Domain.Terminations.GenerationNumberTermination"/> class.
/// </summary>
/// <remarks>
/// The default expected generation number is 100.
/// </remarks>
public GenerationNumberTermination() : this(100)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="GeneticSharp.Domain.Terminations.GenerationNumberTermination"/> class.
/// </summary>
/// <param name="expectedGenerationNumber">The generation number to consider the termination has been reached.</param>
public GenerationNumberTermination(int expectedGenerationNumber)
{
ExpectedGenerationNumber = expectedGenerationNumber;
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the expected generation number to consider that termination has been reached.
/// </summary>
/// <value>The generation number.</value>
public int ExpectedGenerationNumber { get; set; }
#endregion
#region Methods
/// <summary>
/// Determines whether the specified geneticAlgorithm reached the termination condition.
/// </summary>
/// <returns>True if termination has been reached, otherwise false.</returns>
/// <param name="geneticAlgorithm">The genetic algorithm.</param>
protected override bool PerformHasReached(IGeneticAlgorithm geneticAlgorithm)
{
return geneticAlgorithm.GenerationsNumber >= ExpectedGenerationNumber;
}
#endregion
}
}