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