Free cookie consent management tool by TermsFeed Policy Generator

source: branches/jschiess/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/TemperatureController.cs @ 14702

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

#1836 SA reheating strategies: Added basic temperature reset strategy

File size: 7.1 KB
Line 
1#region License Information
2
3/* HeuristicLab
4 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
5 *
6 * This file is part of HeuristicLab.
7 *
8 * HeuristicLab is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * HeuristicLab is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#endregion
23
24using System;
25using System.Linq;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29using HeuristicLab.Operators;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32
33namespace HeuristicLab.Algorithms.SimulatedAnnealing
34{
35    [Item("TemperatureController", "Decides based on information from the heatingoperator, whether to use cooling or heating and calls the appropriate operator.")]
36    [StorableClass]
37    public class TemperatureController : SingleSuccessorOperator
38    {
39        #region Strings
40        private const string ReheatingOperatorName = "ReheatingOperator";
41        private const string AnnealingOperatorName = "AnnealingOperator";
42        private const string MaximumIterationsName = "MaximumIterations";
43        private const string LowerTemperatureName = "LowerTemperature";
44        private const string IterationsName = "Iterations";
45        private const string TemperatureStartIndexName = "TemperatureStartIndex";
46        private const string CoolingName = "Cooling";
47        private const string StartTemperatureName = "StartTemperature";
48        private const string EndTemperatureName = "EndTemperature";
49        private const string TemperatureName = "Temperature";
50        private const string IsAcceptedName = "IsAccepted";
51        private const string AcceptanceMemoryName = "AcceptanceMemory";
52        private const string ReheatCountName = "ReheatCount";
53        #endregion
54
55        #region Parameter Properties
56        public ILookupParameter<DoubleValue> TemperatureParameter
57        {
58            get { return (ILookupParameter<DoubleValue>)Parameters[TemperatureName]; }
59        }
60        public IValueLookupParameter<DoubleValue> LowerTemperatureParameter
61        {
62            get { return (IValueLookupParameter<DoubleValue>)Parameters[LowerTemperatureName]; }
63        }
64        public ILookupParameter<DoubleValue> StartTemperatureParameter
65        {
66            get { return (ILookupParameter<DoubleValue>)Parameters[StartTemperatureName]; }
67        }
68        public ILookupParameter<DoubleValue> EndTemperatureParameter
69        {
70            get { return (ILookupParameter<DoubleValue>)Parameters[EndTemperatureName]; }
71        }
72        public ILookupParameter<IntValue> TemperatureStartIndexParameter
73        {
74            get { return (ILookupParameter<IntValue>)Parameters[TemperatureStartIndexName]; }
75        }
76        public ILookupParameter<BoolValue> CoolingParameter
77        {
78            get { return (ILookupParameter<BoolValue>)Parameters[CoolingName]; }
79        }
80        public ILookupParameter<IntValue> IterationsParameter
81        {
82            get { return (ILookupParameter<IntValue>)Parameters[IterationsName]; }
83        }
84        public IValueLookupParameter<IntValue> MaximumIterationsParameter
85        {
86            get { return (IValueLookupParameter<IntValue>)Parameters[MaximumIterationsName]; }
87        }
88        public IValueLookupParameter<IOperator> AnnealingOperatorParameter
89        {
90            get { return (IValueLookupParameter<IOperator>)Parameters[AnnealingOperatorName]; }
91        }
92        public IValueLookupParameter<IReheatingOperator> ReheatingOperatorParameter
93        {
94            get { return (IValueLookupParameter<IReheatingOperator>)Parameters[ReheatingOperatorName]; }
95        }
96        public ILookupParameter<BoolValue> IsAcceptedParameter
97        {
98            get { return (ILookupParameter<BoolValue>)Parameters[IsAcceptedName]; }
99        }
100        public ILookupParameter<ItemList<BoolValue>> AcceptanceMemoryParameter
101        {
102            get { return (ILookupParameter<ItemList<BoolValue>>)Parameters[AcceptanceMemoryName]; }
103        }
104        public ILookupParameter<IntValue> ReheatCountParameter
105        {
106            get { return (ILookupParameter<IntValue>)Parameters[ReheatCountName]; }
107        }
108        #endregion
109
110        [StorableConstructor]
111        protected TemperatureController(bool deserializing) : base(deserializing) { }
112        protected TemperatureController(TemperatureController original, Cloner cloner) : base(original, cloner) { }
113        public TemperatureController()
114          : base()
115        {
116            Parameters.Add(new LookupParameter<DoubleValue>(TemperatureName, "The current temperature."));
117            Parameters.Add(new ValueLookupParameter<DoubleValue>(LowerTemperatureName, "The lower bound of the temperature."));
118            Parameters.Add(new LookupParameter<IntValue>(IterationsName, "The number of iterations."));
119            Parameters.Add(new ValueLookupParameter<IntValue>(MaximumIterationsName, "The maximum number of iterations which should be processed."));
120            Parameters.Add(new ValueLookupParameter<IOperator>(AnnealingOperatorName, "The operator that cools the temperature."));
121            Parameters.Add(new ValueLookupParameter<IReheatingOperator>(ReheatingOperatorName, "The operator that reheats the temperature if necessary."));
122            Parameters.Add(new LookupParameter<IntValue>(TemperatureStartIndexName, "The index where the annealing or heating was last changed."));
123            Parameters.Add(new LookupParameter<BoolValue>(CoolingName, "True when the temperature should be cooled, false otherwise."));
124            Parameters.Add(new LookupParameter<DoubleValue>(StartTemperatureName, "The temperature from which cooling or reheating should occur."));
125            Parameters.Add(new LookupParameter<DoubleValue>(EndTemperatureName, "The temperature to which should be cooled or heated."));
126            Parameters.Add(new LookupParameter<BoolValue>(IsAcceptedName, "Whether the move was accepted or not."));
127            Parameters.Add(new LookupParameter<ItemList<BoolValue>>(AcceptanceMemoryName, "Memorizes the last N acceptance decisions."));
128            Parameters.Add(new LookupParameter<IntValue>(ReheatCountName, "The number of reheats."));
129        }
130
131        public override IDeepCloneable Clone(Cloner cloner)
132        {
133            return new TemperatureController(this, cloner);
134        }
135
136        public override IOperation Apply()
137        {
138            return new OperationCollection {
139                    ExecutionContext.CreateOperation(ReheatingOperatorParameter.ActualValue),
140                    base.Apply()
141                };
142        }
143    }
144}
Note: See TracBrowser for help on using the repository browser.