-
Notifications
You must be signed in to change notification settings - Fork 3
/
StopAtEvaluation.cs
31 lines (25 loc) · 993 Bytes
/
StopAtEvaluation.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
using System.Linq;
using GeneticAlgorithm.Exceptions;
using GeneticAlgorithm.Interfaces;
namespace GeneticAlgorithm.StopManagers
{
public class StopAtEvaluation : IStopManager
{
private double evaluationToStopAt;
/// <summary>
/// Will stop when we reach a max evaluation equal to or greater then "evaluationToStopAt"
/// </summary>
public StopAtEvaluation(double evaluationToStopAt)
{
if (evaluationToStopAt < 0)
throw GeneticAlgorithmArgumentException.SmallerThanZeroException(nameof(evaluationToStopAt), evaluationToStopAt);
this.evaluationToStopAt = evaluationToStopAt;
}
public bool ShouldStop(Population population, IEnvironment environment, int generation) =>
population.GetEvaluations().Any(evaluation => evaluation >= evaluationToStopAt);
public void AddGeneration(Population population)
{
// Do nothing
}
}
}