#region License Information /* HeuristicLab * Copyright (C) 2002-2015 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.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Optimization.Operators { /// /// Modifies the value by exponential fall (steep fall initially, slow fall to the end) or rise (slow rise initially, fast rise to the end). /// [Item("ExponentialDiscreteDoubleValueModifier", @"Modifies the value by exponential fall (steep fall initially, slow fall to the end) or rise (slow rise initially, fast rise to the end). This uses a standard exponential distribution and yields a base which is implicitly derived by start and end indices and values.")] [StorableClass("D79E2DAE-8A3C-4EE3-9776-A8F6680D2990")] public class ExponentialDiscreteDoubleValueModifier : DiscreteDoubleValueModifier { [StorableConstructor] protected ExponentialDiscreteDoubleValueModifier(bool deserializing) : base(deserializing) { } protected ExponentialDiscreteDoubleValueModifier(ExponentialDiscreteDoubleValueModifier original, Cloner cloner) : base(original, cloner) { } public ExponentialDiscreteDoubleValueModifier() : base() { } public override IDeepCloneable Clone(Cloner cloner) { return new ExponentialDiscreteDoubleValueModifier(this, cloner); } /// /// Calculates a new value based on exponential decay or growth. /// /// Thrown when endValue or startValue or both are 0. /// The last value. /// The start value. /// The end value. /// The current index. /// The start index. /// The end index. /// The new value. protected override double Modify(double value, double startValue, double endValue, int index, int startIndex, int endIndex) { if (endValue <= 0 || startValue <= 0) throw new ArgumentException("startValue and endValue must be greater than 0."); double b = Math.Pow(endValue / startValue, 1.0 / (endIndex - startIndex)); return startValue * Math.Pow(b, index - startIndex); } } }