Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.RealVector/MichalewiczNonUniformOnePositionManipulator.cs @ 1445

Last change on this file since 1445 was 1184, checked in by vdorfer, 16 years ago

Created API documentation for HeuristicLab.RealVector namespace (#331)

File size: 6.0 KB
RevLine 
[104]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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 System.Collections.Generic;
24using System.Text;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27
28namespace HeuristicLab.RealVector {
[1184]29  /// <summary>
30  /// Michalewicz, Z. (1992). Genetic Algorithms + Data Structures = Evolution Programs<br/>
31  /// Non-uniformly distributed change of one position of a real vector.
32  /// </summary>
[104]33  public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulatorBase {
[1184]34    /// <inheritdoc select="summary"/>
[104]35    public override string Description {
36      get { return
37@"Non-uniformly distributed change of one position of a real vector (Michalewicz 1992)
38Initially, the space will be searched uniformly and very locally at later stages. This increases the probability of generating the new number closer to its successor instead of a random number.
39
40Michalewicz, Z. (1992). Genetic Algorithms + Data Structures = Evolution Programs. Springer Verlag.";
41      }
42    }
43
[1184]44    /// <summary>
45    /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with five
46    /// variable infos (<c>Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>, <c>MaximumGenerations</c>
47    /// and <c>GenerationsDependency</c>).
48    /// </summary>
[104]49    public MichalewiczNonUniformOnePositionManipulator()
50      : base() {
51      AddVariableInfo(new VariableInfo("Minimum", "Minimum of the sampling range for the vector element (included)", typeof(DoubleData), VariableKind.In));
52      AddVariableInfo(new VariableInfo("Maximum", "Maximum of the sampling range for the vector element (excluded)", typeof(DoubleData), VariableKind.In));
53      AddVariableInfo(new VariableInfo("CurrentGeneration", "Current Generation of the algorithm", typeof(IntData), VariableKind.In));
54      AddVariableInfo(new VariableInfo("MaximumGenerations", "Maximum number of Generations", typeof(IntData), VariableKind.In));
55      VariableInfo genDepInfo = new VariableInfo("GenerationsDependency", "Specifies the degree of dependency on the number of generations", typeof(IntData), VariableKind.In);
56      genDepInfo.Local = true;
57      AddVariableInfo(genDepInfo);
58      AddVariable(new Variable("GenerationsDependency", new IntData(5)));
59    }
60
[1184]61    /// <summary>
62    /// Performs a non uniformly distributed one position manipulation on the given
63    /// real <paramref name="vector"/>, published by Z. Michalewicz, 1992.
64    /// </summary>
65    /// <remarks>Calls <see cref="Apply"/>.</remarks>
66    /// <param name="scope">The current scope.</param>
67    /// <param name="random">The random number generator.</param>
68    /// <param name="vector">The real vector to manipulate.</param>
69    /// <returns>The manipulated real vector.</returns>
[104]70    protected override double[] Manipulate(IScope scope, IRandom random, double[] vector) {
71      double min = GetVariableValue<DoubleData>("Minimum", scope, true).Data;
72      double max = GetVariableValue<DoubleData>("Maximum", scope, true).Data;
73      int currentGeneration = GetVariableValue<IntData>("CurrentGeneration", scope, true).Data;
74      int maximumGenerations = GetVariableValue<IntData>("MaximumGenerations", scope, true).Data;
75      int generationsDependency = GetVariableValue<IntData>("GenerationsDependency", scope, true).Data;
76      return Apply(random, vector, min, max, currentGeneration, maximumGenerations, generationsDependency);
77    }
78
[1184]79    /// <summary>
80    /// Performs a non uniformly distributed one position manipulation on the given
81    /// real <paramref name="vector"/>, published by Z. Michalewicz, 1992.
82    /// </summary>
83    /// <param name="random">The random number generator.</param>
84    /// <param name="vector">The real vector to manipulate.</param>
85    /// <param name="min">The minimum value of the sampling range for the vector element (inclusive).</param>
86    /// <param name="max">The maximum value of the sampling range for the vector element (exclusive).</param>
87    /// <param name="currentGeneration">The current generation of the algorithm.</param>
88    /// <param name="maximumGenerations">Maximum number of generations.</param>
89    /// <param name="generationsDependency">Specifies the degree of dependency on the number of generations.</param>
90    /// <returns>The manipulated real vector.</returns>
[104]91    public static double[] Apply(IRandom random, double[] vector, double min, double max, int currentGeneration, int maximumGenerations, int generationsDependency) {
92      int length = vector.Length;
93      double[] result = new double[length];
94      int pos = random.Next(length);
95
96      if (random.NextDouble() < 0.5) {
97        vector[pos] = vector[pos] + Delta(random, currentGeneration, max - vector[pos], maximumGenerations, generationsDependency);
98      } else {
99        vector[pos] = vector[pos] - Delta(random, currentGeneration, vector[pos] - min, maximumGenerations, generationsDependency);
100      }
101      return vector;
102    }
103
104    // returns a value between 0 and y (both included)
105    private static double Delta(IRandom random, int currentGeneration, double y, int maximumGenerations, int generationsDependency) {
106      return y * (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentGeneration / maximumGenerations, generationsDependency)));
107    }
108  }
109}
Note: See TracBrowser for help on using the repository browser.