-
Notifications
You must be signed in to change notification settings - Fork 1
/
RandomKPointMutation.cs
39 lines (32 loc) · 1.01 KB
/
RandomKPointMutation.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
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Georgia
{
public abstract class RandomKPointMutation : IMutationStrategy
{
private int _numberOfMutations;
public double MutationRate { get; set; }
public RandomKPointMutation(double mutationRate, int numMutations)
{
_numberOfMutations = numMutations;
MutationRate = mutationRate;
}
#region IMutationStrategy Members
public IChromosome Mutate(IChromosome c)
{
Random prng = RandomFactory.Instance();
IChromosome ret = c as IChromosome;
int index;
for (int i = 0; i < _numberOfMutations; i++)
{
index = prng.Next(0, ret.Count);
ret = Perturb(ret, index);
}
return ret;
}
public abstract IChromosome Perturb(IChromosome c, int position);
#endregion
}
}