Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 14555 was 14555, checked in by jschiess, 8 years ago

#1836 SA reheating strategies: Refactoring, Added Connolly Reheater Operator

File size: 6.8 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        #endregion
53
54        #region Parameter Properties
55        public ILookupParameter<DoubleValue> TemperatureParameter
56        {
57            get { return (ILookupParameter<DoubleValue>)Parameters[TemperatureName]; }
58        }
59        public IValueLookupParameter<DoubleValue> LowerTemperatureParameter
60        {
61            get { return (IValueLookupParameter<DoubleValue>)Parameters[LowerTemperatureName]; }
62        }
63        public ILookupParameter<DoubleValue> StartTemperatureParameter
64        {
65            get { return (ILookupParameter<DoubleValue>)Parameters[StartTemperatureName]; }
66        }
67        public ILookupParameter<DoubleValue> EndTemperatureParameter
68        {
69            get { return (ILookupParameter<DoubleValue>)Parameters[EndTemperatureName]; }
70        }
71        public ILookupParameter<IntValue> TemperatureStartIndexParameter
72        {
73            get { return (ILookupParameter<IntValue>)Parameters[TemperatureStartIndexName]; }
74        }
75        public ILookupParameter<BoolValue> CoolingParameter
76        {
77            get { return (ILookupParameter<BoolValue>)Parameters[CoolingName]; }
78        }
79        public ILookupParameter<IntValue> IterationsParameter
80        {
81            get { return (ILookupParameter<IntValue>)Parameters[IterationsName]; }
82        }
83        public IValueLookupParameter<IntValue> MaximumIterationsParameter
84        {
85            get { return (IValueLookupParameter<IntValue>)Parameters[MaximumIterationsName]; }
86        }
87        public IValueLookupParameter<IOperator> AnnealingOperatorParameter
88        {
89            get { return (IValueLookupParameter<IOperator>)Parameters[AnnealingOperatorName]; }
90        }
91        public IValueLookupParameter<IReheatingOperator> ReheatingOperatorParameter
92        {
93            get { return (IValueLookupParameter<IReheatingOperator>)Parameters[ReheatingOperatorName]; }
94        }
95        public ILookupParameter<BoolValue> IsAcceptedParameter
96        {
97            get { return (ILookupParameter<BoolValue>)Parameters[IsAcceptedName]; }
98        }
99        public ILookupParameter<ItemList<BoolValue>> AcceptanceMemoryParameter
100        {
101            get { return (ILookupParameter<ItemList<BoolValue>>)Parameters[AcceptanceMemoryName]; }
102        }
103        #endregion
104
105        [StorableConstructor]
106        protected TemperatureController(bool deserializing) : base(deserializing) { }
107        protected TemperatureController(TemperatureController original, Cloner cloner) : base(original, cloner) { }
108        public TemperatureController()
109          : base()
110        {
111            Parameters.Add(new LookupParameter<DoubleValue>(TemperatureName, "The current temperature."));
112            Parameters.Add(new ValueLookupParameter<DoubleValue>(LowerTemperatureName, "The lower bound of the temperature."));
113            Parameters.Add(new LookupParameter<IntValue>(IterationsName, "The number of iterations."));
114            Parameters.Add(new ValueLookupParameter<IntValue>(MaximumIterationsName, "The maximum number of iterations which should be processed."));
115            Parameters.Add(new ValueLookupParameter<IOperator>(AnnealingOperatorName, "The operator that cools the temperature."));
116            Parameters.Add(new ValueLookupParameter<IReheatingOperator>(ReheatingOperatorName, "The operator that reheats the temperature if necessary."));
117            Parameters.Add(new LookupParameter<IntValue>(TemperatureStartIndexName, "The index where the annealing or heating was last changed."));
118            Parameters.Add(new LookupParameter<BoolValue>(CoolingName, "True when the temperature should be cooled, false otherwise."));
119            Parameters.Add(new LookupParameter<DoubleValue>(StartTemperatureName, "The temperature from which cooling or reheating should occur."));
120            Parameters.Add(new LookupParameter<DoubleValue>(EndTemperatureName, "The temperature to which should be cooled or heated."));
121            Parameters.Add(new LookupParameter<BoolValue>(IsAcceptedName, "Whether the move was accepted or not."));
122            Parameters.Add(new LookupParameter<ItemList<BoolValue>>(AcceptanceMemoryName, "Memorizes the last N acceptance decisions."));
123        }
124
125        public override IDeepCloneable Clone(Cloner cloner)
126        {
127            return new TemperatureController(this, cloner);
128        }
129
130        public override IOperation Apply()
131        {
132            return new OperationCollection {
133                    ExecutionContext.CreateOperation(ReheatingOperatorParameter.ActualValue),
134                    base.Apply()
135                };
136        }
137    }
138}
Note: See TracBrowser for help on using the repository browser.