-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDoubleBoundaryMutationManager.cs
More file actions
29 lines (25 loc) · 945 Bytes
/
Copy pathDoubleBoundaryMutationManager.cs
File metadata and controls
29 lines (25 loc) · 945 Bytes
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
using GeneticAlgorithm.Components.Interfaces;
namespace GeneticAlgorithm.Components.MutationManagers
{
/// <summary>
/// This mutation operator replaces the genome with either lower or upper bound randomly.
/// The probability of a bit being replaced is 1 / vector-length.
/// </summary>
public class DoubleBoundaryMutationManager : IMutationManager<double>
{
private readonly double minValue;
private readonly double maxValue;
public DoubleBoundaryMutationManager(double minValue, double maxValue)
{
this.minValue = minValue;
this.maxValue = maxValue;
}
public double[] Mutate(double[] vector)
{
for (int i = 0; i < vector.Length; i++)
if (ProbabilityUtils.P(1.0 / vector.Length))
vector[i] = ProbabilityUtils.P(0.5) ? maxValue : minValue;
return vector;
}
}
}