-
-
Notifications
You must be signed in to change notification settings - Fork 334
/
FitnessThresholdTermination.cs
54 lines (50 loc) · 1.88 KB
/
FitnessThresholdTermination.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
using System.ComponentModel;
namespace GeneticSharp
{
/// <summary>
/// Fitness Threshold Termination
/// <remarks>
/// The genetic algorithm will be terminate when the best chromosome reach the expected fitness.
/// </remarks>
/// </summary>
[DisplayName("Fitness Threshold")]
public class FitnessThresholdTermination : TerminationBase
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="GeneticSharp.FitnessThresholdTermination"/> class.
/// </summary>
/// <remarks>
/// The default expected fitness is 1.00.
/// </remarks>
public FitnessThresholdTermination() : this(1.00)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="GeneticSharp.FitnessThresholdTermination"/> class.
/// </summary>
/// <param name="expectedFitness">Expected fitness.</param>
public FitnessThresholdTermination(double expectedFitness)
{
ExpectedFitness = expectedFitness;
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the expected fitness to consider that termination has been reached.
/// </summary>
public double ExpectedFitness { get; set; }
#endregion
#region implemented abstract members of TerminationBase
/// <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.BestChromosome.Fitness >= ExpectedFitness;
}
#endregion
}
}