forked from giacomelli/GeneticSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TerminationBase.cs
47 lines (41 loc) · 1.86 KB
/
TerminationBase.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
using GeneticSharp.Infrastructure.Framework.Texts;
using GeneticSharp.Infrastructure.Framework.Commons;
namespace GeneticSharp.Domain.Terminations
{
/// <summary>
/// Base class for ITerminations implementations.
/// </summary>
public abstract class TerminationBase : ITermination
{
#region Fields
private bool m_hasReached;
#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>
public bool HasReached(IGeneticAlgorithm geneticAlgorithm)
{
ExceptionHelper.ThrowIfNull("geneticAlgorithm", geneticAlgorithm);
m_hasReached = PerformHasReached(geneticAlgorithm);
return m_hasReached;
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents the current <see cref="GeneticSharp.Domain.Terminations.LogicalOperatorTerminationBase"/>.
/// </summary>
/// <returns>A <see cref="System.String"/> that represents the current <see cref="GeneticSharp.Domain.Terminations.LogicalOperatorTerminationBase"/>.</returns>
public override string ToString()
{
return "{0} (HasReached: {1})".With(GetType().Name, m_hasReached);
}
/// <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 abstract bool PerformHasReached(IGeneticAlgorithm geneticAlgorithm);
#endregion
}
}