1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Common;
|
---|
6 | using HeuristicLab.Core;
|
---|
7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Encodings.BinaryVectorEncoding {
|
---|
10 | /// <summary>
|
---|
11 | /// Flips exactly one bit of a binary vector.
|
---|
12 | /// </summary>
|
---|
13 | /// <remarks>
|
---|
14 | /// It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.
|
---|
15 | /// </remarks>
|
---|
16 | [Item("SinglePositionBitflipManipulator", "Flips exactly one bit of a binary vector. It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")]
|
---|
17 | [StorableClass]
|
---|
18 | public class SinglePositionBitflipManipulator: BinaryVectorManipulator {
|
---|
19 | /// <summary>
|
---|
20 | /// Performs the single position bitflip mutation on a binary vector.
|
---|
21 | /// </summary>
|
---|
22 | /// <param name="random">The random number generator to use.</param>
|
---|
23 | /// <param name="vector">The vector that should be manipulated.</param>
|
---|
24 | public static void Apply(IRandom random, BinaryVector vector) {
|
---|
25 | int position = random.Next(vector.Length);
|
---|
26 |
|
---|
27 | vector[position] = !vector[position];
|
---|
28 | }
|
---|
29 |
|
---|
30 | /// <summary>
|
---|
31 | /// Forwards the call to <see cref="Apply(IRandom, BinaryVector)"/>.
|
---|
32 | /// </summary>
|
---|
33 | /// <param name="random">The random number generator to use.</param>
|
---|
34 | /// <param name="realVector">The vector of binary values to manipulate.</param>
|
---|
35 | protected override void Manipulate(IRandom random, BinaryVector binaryVector) {
|
---|
36 | Apply(random, binaryVector);
|
---|
37 | }
|
---|
38 | }
|
---|
39 | }
|
---|