Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1836_jschiess/HeuristicLab.Algorithms.SimulatedAnnealing/3.4/ValueTemperatureInitializer.cs @ 18094

Last change on this file since 18094 was 15315, checked in by jschiess, 7 years ago

#1836 SA reheating strategies:
+ Finalized strategies
+ Added temperature initializer mechanism

File size: 4.6 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Data;
4using HeuristicLab.Operators;
5using HeuristicLab.Parameters;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7using System;
8using System.Collections.Generic;
9using System.Linq;
10using System.Text;
11using System.Threading.Tasks;
12
13namespace HeuristicLab.Algorithms.SimulatedAnnealing
14{
15    [Item("BasicTemperatureInitializer", "Sets the initial temperature to a fixed value.")]
16    [StorableClass]
17    public class BasicTemperatureInitializer : SingleSuccessorOperator, ITemperatureInitializer
18    {
19        #region Strings
20        private const string InitialTemperatureName = "InitialTemperature";
21        private const string TemperatureInitializedName = "TemperatureInitialized";
22        private const string InitialTemperatureSetterName = "InitialTemperatureValue";
23        private const string StartTemperatureName = "StartTemperature";
24        private const string TemperatureStartIndexName = "TemperatureStartIndex";
25        private const string TemperatureName = "Temperature";
26        private const string IterationsName = "Iterations";
27        #endregion
28
29        #region Properties
30        public ILookupParameter<DoubleValue> InitialTemperatureParameter
31        {
32            get { return (ILookupParameter<DoubleValue>)Parameters[InitialTemperatureName]; }
33        }
34        public ILookupParameter<BoolValue> TemperatureInitializedParameter
35        {
36            get { return (ILookupParameter<BoolValue>)Parameters[TemperatureInitializedName]; }
37        }
38        public IValueParameter<DoubleValue> InitialTemperatureSetterParameter
39        {
40            get { return (IValueParameter<DoubleValue>)Parameters[InitialTemperatureSetterName]; }
41        }
42        public ILookupParameter<DoubleValue> StartTemperatureParameter
43        {
44            get { return (ILookupParameter<DoubleValue>)Parameters[StartTemperatureName]; }
45        }
46        public ILookupParameter<IntValue> TemperatureStartIndexParameter
47        {
48            get { return (ILookupParameter<IntValue>)Parameters[TemperatureStartIndexName]; }
49        }
50        public ILookupParameter<DoubleValue> TemperatureParameter
51        {
52            get { return (ILookupParameter<DoubleValue>)Parameters[TemperatureName]; }
53        }
54        public ILookupParameter<IntValue> IterationsParameter
55        {
56            get { return (ILookupParameter<IntValue>)Parameters[IterationsName]; }
57        }
58
59        #endregion
60
61        public BasicTemperatureInitializer() : base()
62        {
63            Parameters.Add(new LookupParameter<DoubleValue>(InitialTemperatureName, "Temporary initial temperature field."));
64            Parameters.Add(new ValueParameter<DoubleValue>(InitialTemperatureSetterName, "Sets the initial temperature to this value", new DoubleValue(100)));
65            Parameters.Add(new LookupParameter<BoolValue>(TemperatureInitializedName, "True, if the temperature has already been initialized."));
66            Parameters.Add(new LookupParameter<DoubleValue>(StartTemperatureName, "The temperature from which cooling or reheating should occur."));
67            Parameters.Add(new LookupParameter<IntValue>(TemperatureStartIndexName, "The index where the annealing or heating was last changed."));
68            Parameters.Add(new LookupParameter<DoubleValue>(TemperatureName, "The current temperature."));
69            Parameters.Add(new LookupParameter<IntValue>(IterationsName, "The number of iterations."));
70        }
71
72        [StorableConstructor]
73        protected BasicTemperatureInitializer(bool deserializing) : base(deserializing) { }
74        protected BasicTemperatureInitializer(BasicTemperatureInitializer original, Cloner cloner) : base(original, cloner) { }
75
76
77        public override IDeepCloneable Clone(Cloner cloner)
78        {
79            return new BasicTemperatureInitializer(this, cloner);
80        }
81
82        public override IOperation Apply()
83        {
84            // set temperature to selected value
85            InitialTemperatureParameter.ActualValue.Value = InitialTemperatureSetterParameter.Value.Value;
86            TemperatureParameter.ActualValue.Value = InitialTemperatureSetterParameter.Value.Value;
87            TemperatureStartIndexParameter.ActualValue.Value = Math.Max(0, IterationsParameter.ActualValue.Value - 1);
88            StartTemperatureParameter.ActualValue.Value = TemperatureParameter.ActualValue.Value;
89
90            // indicate that initial temperature is now set
91            TemperatureInitializedParameter.ActualValue.Value = true;
92
93            return base.Apply();
94        }
95    }
96}
Note: See TracBrowser for help on using the repository browser.