Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.RealVector/3.2/BreederGeneticAlgorithmManipulator.cs @ 2036

Last change on this file since 2036 was 1530, checked in by gkronber, 16 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

File size: 5.3 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 {
29  /// <summary>
30  /// Mühlenbein, Schlierkamp-Voosen (1993)
[1184]31  /// Predictive Models for the Breeder Genetic Algorithm I. Continuous Parameter Optimization<br/>
32  /// Changes one position of a real vector by adding/substracting a value of the interval [(2^-15)*range, ..., (2^0)*range], where range is SearchIntervalFactor * (max - min).
[104]33  /// </summary>
34  public class BreederGeneticAlgorithmManipulator : RealVectorManipulatorBase {
[1184]35    /// <inheritdoc select="summary"/>
[104]36    public override string Description {
37      get {
38        return
39@"Breeder Genetic Algorithm Manipulator (Mühlenbein, Schlierkamp-Voosen, 1993). Changes one position of a real vector by adding/substracting a value of the interval [(2^-15)*range, ..., (2^0)*range], where range is SearchIntervalFactor * (max - min).
40
41Mühlenbein, Schlierkamp-Voosen (1993). Predictive Models for the Breeder Genetic Algorithm I. Continuous Parameter Optimization";
42      }
43    }
44
[1184]45    /// <summary>
46    /// Initializes a new instance of <see cref="BreederGeneticAlgorithmManipulator"/> with three variable
47    /// infos (<c>Minimum</c>, <c>Maximum</c> and <c>SearchIntervalFactor</c>).
48    /// </summary>
[104]49    public BreederGeneticAlgorithmManipulator()
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      VariableInfo sifInfo = new VariableInfo("SearchIntervalFactor", "The factor determining the size of the search interval, that will be added/removed to/from the allele selected for manipulation.", typeof(DoubleData), VariableKind.In);
54      sifInfo.Local = true;
55      AddVariableInfo(sifInfo);
56      AddVariable(new Variable("SearchIntervalFactor", new DoubleData(0.1)));
57    }
58
[1184]59    /// <summary>
60    /// Performs a Breeder Genetic Algorithm Manipulation on the given <paramref name="vector"/>.
61    /// </summary>
62    /// <param name="scope">The current scope.</param>
63    /// <param name="random">A random number generator.</param>
64    /// <param name="vector">The real vector to manipulate.</param>
65    /// <param name="min">The minimum number of the sampling range for the vector element (inclusive).</param>
66    /// <param name="max">The maximum number of the sampling range for the vector element (exclusive).</param>
67    /// <param name="searchIntervalFactor">The factor determining the size of the search interval.</param>
68    /// <returns>The manipulated real vector.</returns>
[104]69    public static double[] Apply(IScope scope, IRandom random, double[] vector, double min, double max, double searchIntervalFactor) {
70      int length = vector.Length;
71      int pos = random.Next(length);
72      double range = searchIntervalFactor * (max - min);
73      double value = range * Sigma(random);
74
75      if (random.NextDouble() < 0.5) {
76        vector[pos] = vector[pos] + value;
77      } else {
78        vector[pos] = vector[pos] - value;
79      }
80
81      return vector;
82    }
83
84    private static double Sigma(IRandom random) {
85      double sigma = 0;
86      int limit = 16;
87
88      for (int i = 0; i < limit; i++) {
89        if (random.Next(limit) == 15) {
90          // execute this statement with a probability of 1/16
91          sigma += Math.Pow(2, -i);
92        }
93      }
94
95      return sigma;
96    }
97
[1184]98    /// <summary>
99    /// Performs a Breeder Genetic Algorithm Manipulation on the given <paramref name="vector"/>.
100    /// </summary>
101    /// <remarks>Calls <see cref="Apply"/>.</remarks>
102    /// <param name="scope">The current scope.</param>
103    /// <param name="random">The random number generator.</param>
104    /// <param name="vector">The real vector to manipulate.</param>
105    /// <returns>The manipulated real vector</returns>
[104]106    protected override double[] Manipulate(IScope scope, IRandom random, double[] vector) {
107      double min = GetVariableValue<DoubleData>("Minimum", scope, true).Data;
108      double max = GetVariableValue<DoubleData>("Maximum", scope, true).Data;
109      double searchIntervalFactor = GetVariableValue<DoubleData>("SearchIntervalFactor", scope, true).Data;
110      return Apply(scope, random, vector, min, max, searchIntervalFactor);
111    }
112  }
113}
Note: See TracBrowser for help on using the repository browser.