Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/NoReheatingOperator.cs @ 15295

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

#1836 SA reheating strategies: Refactoring

File size: 4.9 KB
Line 
1using HeuristicLab.Operators;
2using System;
3using System.Collections.Generic;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7using HeuristicLab.Common;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9using HeuristicLab.Core;
10using HeuristicLab.Data;
11using HeuristicLab.Parameters;
12using HeuristicLab.Optimization;
13using HeuristicLab.PluginInfrastructure;
14using HeuristicLab.Analysis;
15
16namespace HeuristicLab.Algorithms.SimulatedAnnealing
17{
18    [Item("-", "No reheats are performed.")]
19    [StorableClass]
20    public class NoReheatingOperator : SingleSuccessorOperator, IReheatingOperator
21    {
22        #region Strings
23        private const string AnnealingOperatorName = "AnnealingOperator";
24        private const string LowerTemperatureName = "LowerTemperature";
25        private const string IterationsName = "Iterations";
26        private const string TemperatureStartIndexName = "TemperatureStartIndex";
27        private const string StartTemperatureName = "StartTemperature";
28        private const string EndTemperatureName = "EndTemperature";
29        private const string TemperatureName = "Temperature";
30        private const string MaximumIterationsName = "MaximumIterations";
31
32
33        #endregion
34        #region Parameters
35        public ILookupParameter<DoubleValue> TemperatureParameter
36        {
37            get { return (ILookupParameter<DoubleValue>)Parameters[TemperatureName]; }
38        }
39        public ILookupParameter<DoubleValue> LowerTemperatureParameter
40        {
41            get { return (ILookupParameter<DoubleValue>)Parameters[LowerTemperatureName]; }
42        }
43        public ILookupParameter<DoubleValue> StartTemperatureParameter
44        {
45            get { return (ILookupParameter<DoubleValue>)Parameters[StartTemperatureName]; }
46        }
47        public ILookupParameter<DoubleValue> EndTemperatureParameter
48        {
49            get { return (ILookupParameter<DoubleValue>)Parameters[EndTemperatureName]; }
50        }
51        public ILookupParameter<IntValue> TemperatureStartIndexParameter
52        {
53            get { return (ILookupParameter<IntValue>)Parameters[TemperatureStartIndexName]; }
54        }
55        public ILookupParameter<IntValue> IterationsParameter
56        {
57            get { return (ILookupParameter<IntValue>)Parameters[IterationsName]; }
58        }
59        public ILookupParameter<IOperator> AnnealingOperatorParameter
60        {
61            get { return (ILookupParameter<IOperator>)Parameters[AnnealingOperatorName]; }
62        }
63        public ILookupParameter<IntValue> MaximumIterationsParameter
64        {
65            get { return (ILookupParameter<IntValue>)Parameters[MaximumIterationsName]; }
66        }
67
68        #endregion
69
70        public NoReheatingOperator() : base()
71        {
72            #region Create parameters
73            Parameters.Add(new LookupParameter<DoubleValue>(TemperatureName, "The current temperature."));
74            Parameters.Add(new LookupParameter<DoubleValue>(LowerTemperatureName, "The lower bound of the temperature."));
75            Parameters.Add(new LookupParameter<IntValue>(IterationsName, "The number of iterations."));
76            Parameters.Add(new LookupParameter<IntValue>(TemperatureStartIndexName, "The index where the annealing or heating was last changed."));
77            Parameters.Add(new LookupParameter<DoubleValue>(StartTemperatureName, "The temperature from which cooling or reheating should occur."));
78            Parameters.Add(new LookupParameter<DoubleValue>(EndTemperatureName, "The temperature to which should be cooled or heated."));
79            Parameters.Add(new LookupParameter<IntValue>(MaximumIterationsName, "The maximum number of iterations which should be processed."));
80            Parameters.Add(new LookupParameter<IOperator>(AnnealingOperatorName, "The operator that cools the temperature."));
81            #endregion
82
83            Parameterize();
84        }
85
86        [StorableConstructor]
87        protected NoReheatingOperator(bool deserializing) : base(deserializing) { }
88        protected NoReheatingOperator(NoReheatingOperator original, Cloner cloner) : base(original, cloner) { }
89
90
91        public override IDeepCloneable Clone(Cloner cloner)
92        {
93            return new NoReheatingOperator(this, cloner);
94        }
95
96        public void Parameterize()
97        {
98        }
99
100        public override IOperation Apply()
101        {
102            TemperatureStartIndexParameter.ActualValue.Value = Math.Max(0, IterationsParameter.ActualValue.Value - 1);
103            StartTemperatureParameter.ActualValue.Value = TemperatureParameter.ActualValue.Value;
104            EndTemperatureParameter.ActualValue.Value = LowerTemperatureParameter.ActualValue.Value;
105            return new OperationCollection {
106                    ExecutionContext.CreateOperation(AnnealingOperatorParameter.ActualValue),
107                    base.Apply()
108                };
109        }
110    }
111}
Note: See TracBrowser for help on using the repository browser.