Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1836_jschiess/HeuristicLab.Algorithms.SimulatedAnnealing/3.4/TemperatureController.cs @ 17456

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

#1836 SA reheating strategies
+ added an adaptive temperature control strategy
+ some refactorings

File size: 7.9 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;
32using HeuristicLab.Optimization;
33
34namespace HeuristicLab.Algorithms.SimulatedAnnealing
35{
36    [Item("TemperatureController", "Responsible to first initialize the temperature and then control the temperature.")]
37    [StorableClass]
38    public class TemperatureController : SingleSuccessorOperator
39    {
40        #region Strings
41        private const string ReheatingOperatorName = "ReheatingOperator";
42        private const string AnnealingOperatorName = "AnnealingOperator";
43        private const string MaximumIterationsName = "MaximumIterations";
44        private const string InitialTemperatureName = "InitialTemperature";
45        private const string LowerTemperatureName = "LowerTemperature";
46        private const string IterationsName = "Iterations";
47        private const string TemperatureStartIndexName = "TemperatureStartIndex";
48        private const string CoolingName = "Cooling";
49        private const string StartTemperatureName = "StartTemperature";
50        private const string EndTemperatureName = "EndTemperature";
51        private const string TemperatureName = "Temperature";
52        private const string IsAcceptedName = "IsAccepted";
53        private const string ConsecutiveRejectedSolutionsCountName = "ConsecutiveRejectedSolutions";
54        private const string AverageAcceptanceRatioName = "AverageAcceptanceRatio";
55        private const string AcceptanceMemoryName = "AcceptanceMemory";
56        private const string LastQualityName = "LastQuality";
57        private const string UphillMovesMemoryName = "UphillMovesMemory";
58        private const string MaximizationName = "Maximization";
59        private const string MoveQualityName = "MoveQuality";
60        private const string CurrentRandomWalkStepName = "CurrentRandomWalkStep";
61        private const string LastAcceptedQualityName = "LastAcceptedQuality";
62        private const string TemperatureInitializerName = "TemperatureInitializer";
63        private const string TemperatureInitializedName = "TemperatureInitialized";
64        #endregion
65
66        #region Parameter Properties
67        public IValueLookupParameter<IReheatingOperator> ReheatingOperatorParameter
68        {
69            get { return (IValueLookupParameter<IReheatingOperator>)Parameters[ReheatingOperatorName]; }
70        }
71        public IValueLookupParameter<ITemperatureInitializer> TemperatureInitializerParameter
72        {
73            get { return (IValueLookupParameter<ITemperatureInitializer>)Parameters[TemperatureInitializerName]; }
74        }
75        public ILookupParameter<BoolValue> TemperatureInitializedParameter
76        {
77            get { return (ILookupParameter<BoolValue>)Parameters[TemperatureInitializedName]; }
78        }
79        #endregion
80
81        [StorableConstructor]
82        protected TemperatureController(bool deserializing) : base(deserializing) { }
83        protected TemperatureController(TemperatureController original, Cloner cloner) : base(original, cloner) { }
84        public TemperatureController()
85          : base()
86        {
87            Parameters.Add(new LookupParameter<DoubleValue>(TemperatureName, "The current temperature."));
88            Parameters.Add(new ValueLookupParameter<DoubleValue>(LowerTemperatureName, "The lower bound of the temperature."));
89            Parameters.Add(new LookupParameter<IntValue>(IterationsName, "The number of iterations."));
90            Parameters.Add(new ValueLookupParameter<IntValue>(MaximumIterationsName, "The maximum number of iterations which should be processed."));
91            Parameters.Add(new ValueLookupParameter<BoolValue>(MaximizationName, "True if the problem is a maximization problem, otherwise false."));
92            Parameters.Add(new ValueLookupParameter<IDiscreteDoubleValueModifier>(AnnealingOperatorName, "The operator that cools the temperature."));
93            Parameters.Add(new ValueLookupParameter<IReheatingOperator>(ReheatingOperatorName, "The operator that reheats the temperature if necessary."));
94            Parameters.Add(new LookupParameter<IntValue>(TemperatureStartIndexName, "The index where the annealing or heating was last changed."));
95            Parameters.Add(new LookupParameter<BoolValue>(CoolingName, "True when the temperature should be cooled, false otherwise."));
96            Parameters.Add(new LookupParameter<DoubleValue>(StartTemperatureName, "The temperature from which cooling or reheating should occur."));
97            Parameters.Add(new LookupParameter<DoubleValue>(EndTemperatureName, "The temperature to which should be cooled or heated."));
98            Parameters.Add(new LookupParameter<BoolValue>(IsAcceptedName, "Whether the move was accepted or not."));
99            Parameters.Add(new LookupParameter<ItemList<BoolValue>>(AcceptanceMemoryName, "Memorizes the last N acceptance decisions."));
100            Parameters.Add(new LookupParameter<DoubleValue>(InitialTemperatureName, "The initial temperature."));
101
102            Parameters.Add(new LookupParameter<ItemList<DoubleValue>>(UphillMovesMemoryName, "Memorizes the last 100 uphill moves."));
103            Parameters.Add(new LookupParameter<DoubleValue>(MoveQualityName, "The value which represents the quality of a move."));
104            Parameters.Add(new LookupParameter<DoubleValue>(LastQualityName, "The value which represents the quality of the last move."));
105            Parameters.Add(new LookupParameter<IntValue>(ConsecutiveRejectedSolutionsCountName, "Amount of consecutive rejected solutions."));
106            Parameters.Add(new LookupParameter<DoubleValue>(AverageAcceptanceRatioName, "Average acceptance over full acceptance memory."));
107            Parameters.Add(new LookupParameter<IntValue>(CurrentRandomWalkStepName, "Current random walk step."));
108            Parameters.Add(new LookupParameter<DoubleValue>(LastAcceptedQualityName, "Quality of last accepted solution."));
109
110            Parameters.Add(new ValueLookupParameter<ITemperatureInitializer>(TemperatureInitializerName, "The operator that initilized the temperature."));
111            Parameters.Add(new LookupParameter<BoolValue>(TemperatureInitializedName, "True, if the temperature has already been initialized."));
112
113        }
114
115        public override IDeepCloneable Clone(Cloner cloner)
116        {
117            return new TemperatureController(this, cloner);
118        }
119
120        public override IOperation Apply()
121        {
122
123            if (!TemperatureInitializedParameter.ActualValue.Value)
124            {
125                return new OperationCollection
126                {
127                    ExecutionContext.CreateOperation(TemperatureInitializerParameter.ActualValue),
128                    base.Apply()
129                };
130            }
131            else
132            {
133                return new OperationCollection {
134                    ExecutionContext.CreateOperation(ReheatingOperatorParameter.ActualValue),
135                    base.Apply()
136                };
137            }
138        }
139    }
140}
Note: See TracBrowser for help on using the repository browser.