Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Manipulators/MichalewiczNonUniformOnePositionManipulator.cs @ 2915

Last change on this file since 2915 was 2915, checked in by abeham, 14 years ago

Converted Michalewicz's non-uniform mutation operators #890

File size: 7.5 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 System;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Parameters;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Encodings.RealVector {
29  /// <summary>
30  /// The solution is manipulated with diminishing strength over time. In addition the mutated value is not sampled over the entire domain, but additive at the selected position.<br/>
31  /// Initially, the space will be searched uniformly and very locally at later stages. This increases the probability of generating the new number closer to the current value.
32  /// </summary>
33  /// <remarks>
34  /// It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.
35  /// </remarks>
36  [Item("MichalewiczNonUniformOnePositionManipulator", "It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")]
37  [EmptyStorableClass]
38  public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulator {
39    public ValueLookupParameter<DoubleData> MinimumParameter {
40      get { return (ValueLookupParameter<DoubleData>)Parameters["Minimum"]; }
41    }
42    public ValueLookupParameter<DoubleData> MaximumParameter {
43      get { return (ValueLookupParameter<DoubleData>)Parameters["Maximum"]; }
44    }
45    public LookupParameter<IntData> GenerationParameter {
46      get { return (LookupParameter<IntData>)Parameters["Generation"]; }
47    }
48    public LookupParameter<IntData> MaximumGenerationsParameter {
49      get { return (LookupParameter<IntData>)Parameters["MaximumGenerations"]; }
50    }
51    public ValueLookupParameter<DoubleData> GenerationDependencyParameter {
52      get { return (ValueLookupParameter<DoubleData>)Parameters["GenerationDependency"]; }
53    }
54
55    /// <summary>
56    /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with five
57    /// parameters (<c>Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>, <c>MaximumGenerations</c>
58    /// and <c>GenerationDependency</c>).
59    /// </summary>
60    public MichalewiczNonUniformOnePositionManipulator()
61      : base() {
62      Parameters.Add(new ValueLookupParameter<DoubleData>("Minimum", "Minimum of the sampling range for the vector element (included)"));
63      Parameters.Add(new ValueLookupParameter<DoubleData>("Maximum", "Maximum of the sampling range for the vector element (excluded)"));
64      Parameters.Add(new LookupParameter<IntData>("Generation", "Current generation of the algorithm"));
65      Parameters.Add(new LookupParameter<IntData>("MaximumGenerations", "Maximum number of generations"));
66      Parameters.Add(new ValueLookupParameter<DoubleData>("GenerationDependency", "Specifies the degree of dependency on the number of generations", new DoubleData(5)));
67    }
68
69    /// <summary>
70    /// Performs a non uniformly distributed one position manipulation on the given
71    /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="currentGeneration"/> approaches <see cref="maximumGenerations"/>.
72    /// </summary>
73    /// <exception cref="ArgumentException">Thrown when <paramref name="currentGeneration"/> is greater than <paramref name="maximumGenerations"/>.</exception>
74    /// <param name="random">The random number generator.</param>
75    /// <param name="vector">The real vector to manipulate.</param>
76    /// <param name="min">The minimum value of the sampling range for the vector element (inclusive).</param>
77    /// <param name="max">The maximum value of the sampling range for the vector element (exclusive).</param>
78    /// <param name="currentGeneration">The current generation of the algorithm.</param>
79    /// <param name="maximumGenerations">Maximum number of generations.</param>
80    /// <param name="generationsDependency">Specifies the degree of dependency on the number of generations.</param>
81    /// <returns>The manipulated real vector.</returns>
82    public static void Apply(IRandom random, DoubleArrayData vector, DoubleData min, DoubleData max, IntData currentGeneration, IntData maximumGenerations, DoubleData generationsDependency) {
83      if (currentGeneration.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration");
84      int length = vector.Length;
85      int index = random.Next(length);
86
87      double prob = (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentGeneration.Value / maximumGenerations.Value, generationsDependency.Value)));
88
89      if (random.NextDouble() < 0.5) {
90        vector[index] = vector[index] + (max.Value - vector[index]) * prob;
91      } else {
92        vector[index] = vector[index] - (vector[index] - min.Value) * prob;
93      }
94    }
95
96    /// <summary>
97    /// Checks if all parameters are available and forwards the call to <see cref="Apply(IRandom, DoubleArrayData, DoubleData, DoubleData, IntData, IntData, DoubleData)"/>.
98    /// </summary>
99    /// <param name="random">The random number generator.</param>
100    /// <param name="realVector">The real vector that should be manipulated.</param>
101    protected override void Manipulate(IRandom random, DoubleArrayData realVector) {
102      if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MinimumParameter.ActualName + " could not be found.");
103      if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumParameter.ActualName + " could not be found.");
104      if (GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found.");
105      if (MaximumGenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found.");
106      if (GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found.");
107      Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);
108    }
109  }
110}
Note: See TracBrowser for help on using the repository browser.