-
Notifications
You must be signed in to change notification settings - Fork 3
/
RenewAtConvergence.cs
31 lines (26 loc) · 1.26 KB
/
RenewAtConvergence.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 GeneticAlgorithm.Exceptions;
using GeneticAlgorithm.Interfaces;
namespace GeneticAlgorithm.PopulationRenwalManagers
{
/// <summary>
/// Will renew "precentageToRenew" of the population when the difference between the min evaluation and max evaluation is equal to or less than "diff".
/// </summary>
public class RenewAtConvergence : IPopulationRenwalManager
{
private readonly double precentageToRenew;
private readonly IStopManager stopManager;
/// <summary>
/// Will renew "precentageToRenew" of the population when the difference between the min evaluation and max evaluation is equal to or less than "diff".
/// </summary>
public RenewAtConvergence(double diff, double precentageToRenew)
{
precentageToRenew.VerifyPrecentageToRenew();
this.precentageToRenew = precentageToRenew;
stopManager = new StopManagers.StopAtConvergence(diff);
}
public double ShouldRenew(Population population, IEnvironment environment, int generation) =>
stopManager.ShouldStop(population, environment, generation) ? precentageToRenew : 0;
public void AddGeneration(Population population) =>
stopManager.AddGeneration(population);
}
}