#region License Information /* HeuristicLab * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Encodings.RealVectorEncoding { /// /// The solution is manipulated with diminishing strength over time. In addition the mutated value is not sampled over the entire domain, but additive at the selected position.
/// Initially, the space will be searched uniformly and very locally at later stages. This increases the probability of generating the new number closer to the current value. ///
/// /// It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg. /// [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.")] [StorableClass] public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulator { /// /// The current generation. /// public LookupParameter GenerationParameter { get { return (LookupParameter)Parameters["Generations"]; } } /// /// The maximum generation. /// public LookupParameter MaximumGenerationsParameter { get { return (LookupParameter)Parameters["MaximumGenerations"]; } } /// /// The parameter describing how much the mutation should depend on the progress towards the maximum generation. /// public ValueLookupParameter GenerationDependencyParameter { get { return (ValueLookupParameter)Parameters["GenerationDependency"]; } } /// /// Initializes a new instance of with four /// parameters (Bounds, CurrentGeneration, MaximumGenerations /// and GenerationDependency). /// public MichalewiczNonUniformOnePositionManipulator() : base() { Parameters.Add(new LookupParameter("Generations", "Current generation of the algorithm")); Parameters.Add(new LookupParameter("MaximumGenerations", "Maximum number of generations")); Parameters.Add(new ValueLookupParameter("GenerationDependency", "Specifies the degree of dependency on the number of generations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum generations will be taken into account by sampling closer around the current position. Value must be >= 0.", new DoubleValue(5))); } /// /// Performs a non uniformly distributed one position manipulation on the given /// real . The probability of stronger mutations reduces the more approaches . /// /// Thrown when is greater than . /// The random number generator. /// The real vector to manipulate. /// The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled. /// The current generation of the algorithm. /// Maximum number of generations. /// Specifies the degree of dependency on the number of generations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum generations will be taken into account by sampling closer around the current position. Value must be >= 0. /// The manipulated real vector. public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue currentGeneration, IntValue maximumGenerations, DoubleValue generationsDependency) { if (currentGeneration.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration"); if (generationsDependency.Value < 0) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: GenerationsDependency must be >= 0."); int length = vector.Length; int index = random.Next(length); double prob = (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentGeneration.Value / maximumGenerations.Value, generationsDependency.Value))); double min = bounds[index % bounds.Rows, 0]; double max = bounds[index % bounds.Rows, 1]; if (random.NextDouble() < 0.5) { vector[index] = vector[index] + (max - vector[index]) * prob; } else { vector[index] = vector[index] - (vector[index] - min) * prob; } } /// /// Checks if all parameters are available and forwards the call to . /// /// The random number generator. /// The real vector that should be manipulated. protected override void Manipulate(IRandom random, RealVector realVector) { if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found."); if (GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found."); if (MaximumGenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found."); if (GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found."); Apply(random, realVector, BoundsParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue); } } }