1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 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 HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Parameters;
|
---|
27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Encodings.RealVectorEncoding {
|
---|
30 | /// <summary>
|
---|
31 | /// Performs the polynomial manipulation on all positions in the real vector.
|
---|
32 | /// </summary>
|
---|
33 | /// <remarks>
|
---|
34 | /// The polynomial manipulation is implemented as described in Deb, K. & Goyal, M. A. 1996. Combined Genetic Adaptive Search (GeneAS) for Engineering Design Computer Science and Informatics, 26, pp. 30-45.
|
---|
35 | /// It is performed on all positions of a real vector.
|
---|
36 | /// </remarks>
|
---|
37 | [Item("PolynomialAllPositionManipulator", "The polynomial manipulation is implemented as described in Deb, K. & Goyal, M. A. 1996. Combined Genetic Adaptive Search (GeneAS) for Engineering Design Computer Science and Informatics, 26, pp. 30-45. In this operator it is performed on all positions of the real vector.")]
|
---|
38 | [StorableClass]
|
---|
39 | public class PolynomialAllPositionManipulator : RealVectorManipulator {
|
---|
40 | /// <summary>
|
---|
41 | /// The contiguity parameter specifies the shape of the probability density function that controls the mutation. Setting it to 0 is similar to a uniform distribution over the entire manipulation range (specified by <see cref="MaximumManipulationParameter"/>.
|
---|
42 | /// A higher value will shape the density function such that values closer to 0 (little manipulation) are more likely than larger values.
|
---|
43 | /// </summary>
|
---|
44 | public ValueLookupParameter<DoubleValue> ContiguityParameter {
|
---|
45 | get { return (ValueLookupParameter<DoubleValue>)Parameters["Contiguity"]; }
|
---|
46 | }
|
---|
47 | /// <summary>
|
---|
48 | /// The maximum manipulation parameter specifies the range of the manipulation. The value specified here is the highest value the mutation will ever add to the current value.
|
---|
49 | /// </summary>
|
---|
50 | /// <remarks>
|
---|
51 | /// If there are bounds specified the manipulated value is restricted by the given lower and upper bounds.
|
---|
52 | /// </remarks>
|
---|
53 | public ValueLookupParameter<DoubleValue> MaximumManipulationParameter {
|
---|
54 | get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumManipulation"]; }
|
---|
55 | }
|
---|
56 |
|
---|
57 | [StorableConstructor]
|
---|
58 | protected PolynomialAllPositionManipulator(bool deserializing) : base(deserializing) { }
|
---|
59 | protected PolynomialAllPositionManipulator(PolynomialAllPositionManipulator original, Cloner cloner) : base(original, cloner) { }
|
---|
60 | /// <summary>
|
---|
61 | /// Initializes a new instance of <see cref="PolynomialAllPositionManipulator"/> with two parameters
|
---|
62 | /// (<c>Contiguity</c> and <c>MaximumManipulation</c>).
|
---|
63 | /// </summary>
|
---|
64 | public PolynomialAllPositionManipulator()
|
---|
65 | : base() {
|
---|
66 | Parameters.Add(new ValueLookupParameter<DoubleValue>("Contiguity", "Specifies whether the manipulation should produce far stretching (small value) or close (large value) manipulations with higher probability. Valid values must be greater or equal to 0.", new DoubleValue(2)));
|
---|
67 | Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumManipulation", "Specifies the maximum value that should be added or subtracted by the manipulation. If this value is set to 0 no mutation will be performed.", new DoubleValue(1)));
|
---|
68 | }
|
---|
69 |
|
---|
70 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
71 | return new PolynomialAllPositionManipulator(this, cloner);
|
---|
72 | }
|
---|
73 |
|
---|
74 | /// <summary>
|
---|
75 | /// Performs the polynomial mutation on a single position in the real vector.
|
---|
76 | /// </summary>
|
---|
77 | /// <param name="random">The random number generator to use.</param>
|
---|
78 | /// <param name="vector">The vector that should be manipulated.</param>
|
---|
79 | /// <param name="contiguity">A parameter describing the shape of the probability density function which influences the strength of the manipulation.</param>
|
---|
80 | /// <param name="maxManipulation">The maximum strength of the manipulation.</param>
|
---|
81 | public static void Apply(IRandom random, RealVector vector, DoubleValue contiguity, DoubleValue maxManipulation) {
|
---|
82 | if (contiguity.Value < 0) throw new ArgumentException("PolynomialAllPositionManipulator: Contiguity value is smaller than 0", "contiguity");
|
---|
83 | double u, delta = 0;
|
---|
84 |
|
---|
85 | for (int index = 0; index < vector.Length; index++) {
|
---|
86 | u = random.NextDouble();
|
---|
87 | if (u < 0.5) {
|
---|
88 | delta = Math.Pow(2 * u, 1.0 / (contiguity.Value + 1)) - 1.0;
|
---|
89 | } else if (u >= 0.5) {
|
---|
90 | delta = 1.0 - Math.Pow(2.0 - 2.0 * u, 1.0 / (contiguity.Value + 1));
|
---|
91 | }
|
---|
92 |
|
---|
93 | vector[index] += delta * maxManipulation.Value;
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | /// <summary>
|
---|
98 | /// Checks the availability of the parameters and forwards the call to <see cref="Apply(IRandom, RealVector, DoubleValue, DoubleValue)"/>.
|
---|
99 | /// </summary>
|
---|
100 | /// <param name="random">The random number generator to use.</param>
|
---|
101 | /// <param name="realVector">The vector of real values to manipulate.</param>
|
---|
102 | protected override void Manipulate(IRandom random, RealVector realVector) {
|
---|
103 | if (ContiguityParameter.ActualValue == null) throw new InvalidOperationException("PolynomialAllPositionManipulator: Parameter " + ContiguityParameter.ActualName + " could not be found.");
|
---|
104 | if (MaximumManipulationParameter.ActualValue == null) throw new InvalidOperationException("PolynomialAllPositionManipulator: Parameter " + MaximumManipulationParameter.ActualName + " could not be found.");
|
---|
105 | Apply(random, realVector, ContiguityParameter.ActualValue, MaximumManipulationParameter.ActualValue);
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|