-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRenewIfNoImprovment.cs
34 lines (29 loc) · 1.38 KB
/
RenewIfNoImprovment.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
using GeneticAlgorithm.Exceptions;
using GeneticAlgorithm.Interfaces;
using GeneticAlgorithm.StopManagers;
namespace GeneticAlgorithm.PopulationRenwalManagers
{
/// <summary>
/// Will renew "precentageToRenew" of the population when there isn't an improvement of at least "minImprovment" after "generationsToConsider" generations.
/// </summary>
public class RenewIfNoImprovment : IPopulationRenwalManager
{
private readonly double precentageToRenew;
private readonly IStopManager stopManager;
/// <summary>
/// Will renew "precentageToRenew" of the population when there isn't an improvement of at least "minImprovment" after "generationsToConsider" generations.
/// </summary>
public RenewIfNoImprovment(int generationsToConsider, double minImprvment, double precentageToRenew)
{
precentageToRenew.VerifyPrecentageToRenew();
this.precentageToRenew = precentageToRenew;
stopManager = new StopIfNoImprovment(generationsToConsider, minImprvment);
}
public double ShouldRenew(Population population, IEnvironment environment, int generation) =>
stopManager.ShouldStop(population, environment, generation) ? precentageToRenew : 0;
public void AddGeneration(Population population)
{
stopManager.AddGeneration(population);
}
}
}