Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Manipulators/MichalewiczNonUniformAllPositionsManipulator.cs @ 2921

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

updated documentation of some of the operators #890

File size: 8.0 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 values are not sampled over the entire domain, but additive.<br/>
31  /// Initially, the space will be searched uniformly and very locally at later stages. This increases the probability of generating the new numbers 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 MichalewiczNonUniformAllPositionsManipulator : RealVectorManipulator {
39    /// <summary>
40    /// The lower bound of the values in the real vector.
41    /// </summary>
42    public ValueLookupParameter<DoubleData> MinimumParameter {
43      get { return (ValueLookupParameter<DoubleData>)Parameters["Minimum"]; }
44    }
45    /// <summary>
46    /// The upper bound of the values in the real vector.
47    /// </summary>
48    public ValueLookupParameter<DoubleData> MaximumParameter {
49      get { return (ValueLookupParameter<DoubleData>)Parameters["Maximum"]; }
50    }
51    /// <summary>
52    /// The current generation.
53    /// </summary>
54    public LookupParameter<IntData> GenerationParameter {
55      get { return (LookupParameter<IntData>)Parameters["Generation"]; }
56    }
57    /// <summary>
58    /// The maximum generation.
59    /// </summary>
60    public LookupParameter<IntData> MaximumGenerationsParameter {
61      get { return (LookupParameter<IntData>)Parameters["MaximumGenerations"]; }
62    }
63    /// <summary>
64    /// The parameter describing how much the mutation should depend on the progress towards the maximum generation.
65    /// </summary>
66    public ValueLookupParameter<DoubleData> GenerationDependencyParameter {
67      get { return (ValueLookupParameter<DoubleData>)Parameters["GenerationDependency"]; }
68    }
69
70    /// <summary>
71    /// Initializes a new instance of <see cref="MichalewiczNonUniformAllPositionsManipulator"/> with
72    /// five parameters (<c>Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>,
73    /// <c>MaximumGenerations</c> and <c>GenerationDependency</c>).
74    /// </summary>
75    public MichalewiczNonUniformAllPositionsManipulator()
76      : base() {
77      Parameters.Add(new ValueLookupParameter<DoubleData>("Minimum", "Minimum of the sampling range for the vector element (included)"));
78      Parameters.Add(new ValueLookupParameter<DoubleData>("Maximum", "Maximum of the sampling range for the vector element (excluded)"));
79      Parameters.Add(new LookupParameter<IntData>("Generation", "Current generation of the algorithm"));
80      Parameters.Add(new LookupParameter<IntData>("MaximumGenerations", "Maximum number of generations"));
81      Parameters.Add(new ValueLookupParameter<DoubleData>("GenerationDependency", "Specifies the degree of dependency on the number of generations", new DoubleData(5)));
82    }
83
84    /// <summary>
85    /// Performs a non uniformly distributed all position manipulation on the given
86    /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="currentGeneration"/> approaches <see cref="maximumGenerations"/>.
87    /// </summary>
88    /// <exception cref="ArgumentException">Thrown when <paramref name="currentGeneration"/> is greater than <paramref name="maximumGenerations"/>.</exception>
89    /// <param name="random">The random number generator.</param>
90    /// <param name="vector">The real vector to manipulate.</param>
91    /// <param name="min">The minimum value of the sampling range for the vector element (inclusive).</param>
92    /// <param name="max">The maximum value of the sampling range for the vector element (exclusive).</param>
93    /// <param name="currentGeneration">The current generation of the algorithm.</param>
94    /// <param name="maximumGenerations">Maximum number of generations.</param>
95    /// <param name="generationsDependency">Specifies the degree of dependency on the number of generations.</param>
96    /// <returns>The manipulated real vector.</returns>
97    public static void Apply(IRandom random, DoubleArrayData vector, DoubleData min, DoubleData max, IntData currentGeneration, IntData maximumGenerations, DoubleData generationsDependency) {
98      if (currentGeneration.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformAllPositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration");
99      int length = vector.Length;
100
101      double prob = Math.Pow(1 - currentGeneration.Value / maximumGenerations.Value, generationsDependency.Value);
102
103      for (int i = 0; i < length; i++) {
104        if (random.NextDouble() < 0.5) {
105          vector[i] = vector[i] + (max.Value - vector[i]) * (1 - Math.Pow(random.NextDouble(), prob));
106        } else {
107          vector[i] = vector[i] - (vector[i] - min.Value) * (1 - Math.Pow(random.NextDouble(), prob));
108        }
109      }
110    }
111
112    /// <summary>
113    /// Checks if all parameters are available and forwards the call to <see cref="Apply(IRandom, DoubleArrayData, DoubleData, DoubleData, IntData, IntData, DoubleData)"/>.
114    /// </summary>
115    /// <param name="random">The random number generator.</param>
116    /// <param name="realVector">The real vector that should be manipulated.</param>
117    protected override void Manipulate(IRandom random, DoubleArrayData realVector) {
118      if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MinimumParameter.ActualName + " could not be found.");
119      if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MaximumParameter.ActualName + " could not be found.");
120      if (GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found.");
121      if (MaximumGenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found.");
122      if (GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found.");
123      Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);
124    }
125  }
126}
Note: See TracBrowser for help on using the repository browser.