Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Manipulators/SomePositionsBitflipManipulator.cs @ 4068

Last change on this file since 4068 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Core;
23using HeuristicLab.Data;
24using HeuristicLab.Parameters;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26
27namespace HeuristicLab.Encodings.BinaryVectorEncoding {
28  /// <summary>
29  /// Flips some bits of a binary vector.
30  /// </summary>
31  /// <remarks>
32  /// It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg, p. 43.
33  /// </remarks>
34  [Item("SomePositionsBitflipManipulator", "Flips some bits of a binary vector, each position is flipped with a probability of pm. It is implemented as described in Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg, p. 43.")]
35  [StorableClass]
36  public class SomePositionsBitflipManipulator : BinaryVectorManipulator {
37    /// <summary>
38    /// Mmutation probability for each position.
39    /// </summary>
40    public ValueLookupParameter<DoubleValue> MutationProbabilityParameter {
41      get { return (ValueLookupParameter<DoubleValue>)Parameters["MutationProbability"]; }
42    }
43
44    /// <summary>
45    /// Initializes a new instance of <see cref="NPointCrossover"/>
46    /// </summary>
47    public SomePositionsBitflipManipulator() {
48      Parameters.Add(new ValueLookupParameter<DoubleValue>("MutationProbability", "The mutation probability for each position", new DoubleValue(0.2)));
49    }
50
51    /// <summary>
52    /// Performs the some positions bitflip mutation on a binary vector.
53    /// </summary>
54    /// <param name="random">The random number generator to use.</param>
55    /// <param name="vector">The vector that should be manipulated.</param>
56    /// <param name="pm">The probability a bit is flipped.</param>
57    public static void Apply(IRandom random, BinaryVector vector, DoubleValue pm) {
58      for (int i = 0; i < vector.Length; i++) {
59        if (random.NextDouble() < pm.Value) {
60          vector[i] = !vector[i];
61        }
62      }
63    }
64
65    /// <summary>
66    /// Forwards the call to <see cref="Apply(IRandom, BinaryVector)"/>.
67    /// </summary>
68    /// <param name="random">The random number generator to use.</param>
69    /// <param name="realVector">The vector of binary values to manipulate.</param>
70    protected override void Manipulate(IRandom random, BinaryVector binaryVector) {
71      Apply(random, binaryVector, MutationProbabilityParameter.Value);
72    }
73  }
74}
Note: See TracBrowser for help on using the repository browser.