using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HeuristicLab.Algorithms.SimulatedAnnealing { [Item("BasicTemperatureInitializer", "Sets the initial temperature to a fixed value.")] [StorableClass] public class BasicTemperatureInitializer : SingleSuccessorOperator, ITemperatureInitializer { #region Strings private const string InitialTemperatureName = "InitialTemperature"; private const string TemperatureInitializedName = "TemperatureInitialized"; private const string InitialTemperatureSetterName = "InitialTemperatureValue"; private const string StartTemperatureName = "StartTemperature"; private const string TemperatureStartIndexName = "TemperatureStartIndex"; private const string TemperatureName = "Temperature"; private const string IterationsName = "Iterations"; #endregion #region Properties public ILookupParameter InitialTemperatureParameter { get { return (ILookupParameter)Parameters[InitialTemperatureName]; } } public ILookupParameter TemperatureInitializedParameter { get { return (ILookupParameter)Parameters[TemperatureInitializedName]; } } public IValueParameter InitialTemperatureSetterParameter { get { return (IValueParameter)Parameters[InitialTemperatureSetterName]; } } public ILookupParameter StartTemperatureParameter { get { return (ILookupParameter)Parameters[StartTemperatureName]; } } public ILookupParameter TemperatureStartIndexParameter { get { return (ILookupParameter)Parameters[TemperatureStartIndexName]; } } public ILookupParameter TemperatureParameter { get { return (ILookupParameter)Parameters[TemperatureName]; } } public ILookupParameter IterationsParameter { get { return (ILookupParameter)Parameters[IterationsName]; } } #endregion public BasicTemperatureInitializer() : base() { Parameters.Add(new LookupParameter(InitialTemperatureName, "Temporary initial temperature field.")); Parameters.Add(new ValueParameter(InitialTemperatureSetterName, "Sets the initial temperature to this value", new DoubleValue(100))); Parameters.Add(new LookupParameter(TemperatureInitializedName, "True, if the temperature has already been initialized.")); Parameters.Add(new LookupParameter(StartTemperatureName, "The temperature from which cooling or reheating should occur.")); Parameters.Add(new LookupParameter(TemperatureStartIndexName, "The index where the annealing or heating was last changed.")); Parameters.Add(new LookupParameter(TemperatureName, "The current temperature.")); Parameters.Add(new LookupParameter(IterationsName, "The number of iterations.")); } [StorableConstructor] protected BasicTemperatureInitializer(bool deserializing) : base(deserializing) { } protected BasicTemperatureInitializer(BasicTemperatureInitializer original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new BasicTemperatureInitializer(this, cloner); } public override IOperation Apply() { // set temperature to selected value InitialTemperatureParameter.ActualValue.Value = InitialTemperatureSetterParameter.Value.Value; TemperatureParameter.ActualValue.Value = InitialTemperatureSetterParameter.Value.Value; TemperatureStartIndexParameter.ActualValue.Value = Math.Max(0, IterationsParameter.ActualValue.Value - 1); StartTemperatureParameter.ActualValue.Value = TemperatureParameter.ActualValue.Value; // indicate that initial temperature is now set TemperatureInitializedParameter.ActualValue.Value = true; return base.Apply(); } } }