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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Text;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.RealVector {
|
---|
29 | /// <summary>
|
---|
30 | /// Mühlenbein, Schlierkamp-Voosen (1993)
|
---|
31 | /// Predictive Models for the Breeder Genetic Algorithm I. Continuous Parameter Optimization
|
---|
32 | /// </summary>
|
---|
33 | public class BreederGeneticAlgorithmManipulator : RealVectorManipulatorBase {
|
---|
34 | public override string Description {
|
---|
35 | get {
|
---|
36 | return
|
---|
37 | @"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).
|
---|
38 |
|
---|
39 | Mühlenbein, Schlierkamp-Voosen (1993). Predictive Models for the Breeder Genetic Algorithm I. Continuous Parameter Optimization";
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public BreederGeneticAlgorithmManipulator()
|
---|
44 | : base() {
|
---|
45 | AddVariableInfo(new VariableInfo("Minimum", "Minimum of the sampling range for the vector element (included)", typeof(DoubleData), VariableKind.In));
|
---|
46 | AddVariableInfo(new VariableInfo("Maximum", "Maximum of the sampling range for the vector element (excluded)", typeof(DoubleData), VariableKind.In));
|
---|
47 | 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);
|
---|
48 | sifInfo.Local = true;
|
---|
49 | AddVariableInfo(sifInfo);
|
---|
50 | AddVariable(new Variable("SearchIntervalFactor", new DoubleData(0.1)));
|
---|
51 | }
|
---|
52 |
|
---|
53 | public static double[] Apply(IScope scope, IRandom random, double[] vector, double min, double max, double searchIntervalFactor) {
|
---|
54 | int length = vector.Length;
|
---|
55 | int pos = random.Next(length);
|
---|
56 | double range = searchIntervalFactor * (max - min);
|
---|
57 | double value = range * Sigma(random);
|
---|
58 |
|
---|
59 | if (random.NextDouble() < 0.5) {
|
---|
60 | vector[pos] = vector[pos] + value;
|
---|
61 | } else {
|
---|
62 | vector[pos] = vector[pos] - value;
|
---|
63 | }
|
---|
64 |
|
---|
65 | return vector;
|
---|
66 | }
|
---|
67 |
|
---|
68 | private static double Sigma(IRandom random) {
|
---|
69 | double sigma = 0;
|
---|
70 | int limit = 16;
|
---|
71 |
|
---|
72 | for (int i = 0; i < limit; i++) {
|
---|
73 | if (random.Next(limit) == 15) {
|
---|
74 | // execute this statement with a probability of 1/16
|
---|
75 | sigma += Math.Pow(2, -i);
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | return sigma;
|
---|
80 | }
|
---|
81 |
|
---|
82 | protected override double[] Manipulate(IScope scope, IRandom random, double[] vector) {
|
---|
83 | double min = GetVariableValue<DoubleData>("Minimum", scope, true).Data;
|
---|
84 | double max = GetVariableValue<DoubleData>("Maximum", scope, true).Data;
|
---|
85 | double searchIntervalFactor = GetVariableValue<DoubleData>("SearchIntervalFactor", scope, true).Data;
|
---|
86 | return Apply(scope, random, vector, min, max, searchIntervalFactor);
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|