forked from giacomelli/GeneticSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeEvolvingTermination.cs
56 lines (52 loc) · 1.96 KB
/
TimeEvolvingTermination.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
using System;
using System.ComponentModel;
namespace GeneticSharp
{
/// <summary>
/// Time Evolving Termination.
/// <remarks>
/// The genetic algorithm will be terminate when the evolving exceed the max time specified.
/// </remarks>
/// </summary>
[DisplayName("Time Evolving")]
public class TimeEvolvingTermination : TerminationBase
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="GeneticSharp.Domain.Terminations.TimeEvolvingTermination"/> class.
/// </summary>
/// <remarks>
/// The default MaxTime is 1 minute.
/// </remarks>
public TimeEvolvingTermination() : this(TimeSpan.FromMinutes(1))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="GeneticSharp.Domain.Terminations.TimeEvolvingTermination"/> class.
/// </summary>
/// <param name="maxTime">The execution time to consider the termination has been reached.</param>
public TimeEvolvingTermination(TimeSpan maxTime)
{
MaxTime = maxTime;
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the execution max time.
/// </summary>
/// <value>The max time.</value>
public TimeSpan MaxTime { 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.TimeEvolving >= MaxTime;
}
#endregion
}
}