Free cookie consent management tool by TermsFeed Policy Generator

source: branches/jschiess/HeuristicLab.Algorithms.SimulatedAnnealing/3.4/TemperatureController.cs @ 15315

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

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

File size: 8.4 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 TemperatureBeforeReheatName = "TemperatureBeforeReheat";
61        private const string CurrentRandomWalkStepName = "CurrentRandomWalkStep";
62        private const string QualitiesBeforeReheatingName = "QualitiesBeforeReheating";
63        private const string LastAcceptedQualityName = "LastAcceptedQuality";
64        private const string TemperatureInitializerName = "TemperatureInitializer";
65        private const string TemperatureInitializedName = "TemperatureInitialized";
66        #endregion
67
68        #region Parameter Properties
69        public IValueLookupParameter<IReheatingOperator> ReheatingOperatorParameter
70        {
71            get { return (IValueLookupParameter<IReheatingOperator>)Parameters[ReheatingOperatorName]; }
72        }
73        public IValueLookupParameter<ITemperatureInitializer> TemperatureInitializerParameter
74        {
75            get { return (IValueLookupParameter<ITemperatureInitializer>)Parameters[TemperatureInitializerName]; }
76        }
77        public ILookupParameter<BoolValue> TemperatureInitializedParameter
78        {
79            get { return (ILookupParameter<BoolValue>)Parameters[TemperatureInitializedName]; }
80        }
81        #endregion
82
83        [StorableConstructor]
84        protected TemperatureController(bool deserializing) : base(deserializing) { }
85        protected TemperatureController(TemperatureController original, Cloner cloner) : base(original, cloner) { }
86        public TemperatureController()
87          : base()
88        {
89            Parameters.Add(new LookupParameter<DoubleValue>(TemperatureName, "The current temperature."));
90            Parameters.Add(new ValueLookupParameter<DoubleValue>(LowerTemperatureName, "The lower bound of the temperature."));
91            Parameters.Add(new LookupParameter<IntValue>(IterationsName, "The number of iterations."));
92            Parameters.Add(new ValueLookupParameter<IntValue>(MaximumIterationsName, "The maximum number of iterations which should be processed."));
93            Parameters.Add(new ValueLookupParameter<BoolValue>(MaximizationName, "True if the problem is a maximization problem, otherwise false."));
94            Parameters.Add(new ValueLookupParameter<IOperator>(AnnealingOperatorName, "The operator that cools the temperature."));
95            Parameters.Add(new ValueLookupParameter<IReheatingOperator>(ReheatingOperatorName, "The operator that reheats the temperature if necessary."));
96            Parameters.Add(new LookupParameter<IntValue>(TemperatureStartIndexName, "The index where the annealing or heating was last changed."));
97            Parameters.Add(new LookupParameter<BoolValue>(CoolingName, "True when the temperature should be cooled, false otherwise."));
98            Parameters.Add(new LookupParameter<DoubleValue>(StartTemperatureName, "The temperature from which cooling or reheating should occur."));
99            Parameters.Add(new LookupParameter<DoubleValue>(EndTemperatureName, "The temperature to which should be cooled or heated."));
100            Parameters.Add(new LookupParameter<BoolValue>(IsAcceptedName, "Whether the move was accepted or not."));
101            Parameters.Add(new LookupParameter<ItemList<BoolValue>>(AcceptanceMemoryName, "Memorizes the last N acceptance decisions."));
102            Parameters.Add(new LookupParameter<DoubleValue>(InitialTemperatureName, "The initial temperature."));
103
104            Parameters.Add(new LookupParameter<ItemList<DoubleValue>>(UphillMovesMemoryName, "Memorizes the last 100 uphill moves."));
105            Parameters.Add(new LookupParameter<DoubleValue>(MoveQualityName, "The value which represents the quality of a move."));
106            Parameters.Add(new LookupParameter<DoubleValue>(LastQualityName, "The value which represents the quality of the last move."));
107            Parameters.Add(new LookupParameter<IntValue>(ConsecutiveRejectedSolutionsCountName, "Amount of consecutive rejected solutions."));
108            Parameters.Add(new LookupParameter<DoubleValue>(AverageAcceptanceRatioName, "Average acceptance over full acceptance memory."));
109            Parameters.Add(new LookupParameter<IntValue>(CurrentRandomWalkStepName, "Current random walk step."));
110            Parameters.Add(new LookupParameter<DoubleValue>(TemperatureBeforeReheatName, "Temperature before the reheat occured."));
111            Parameters.Add(new LookupParameter<ItemList<DoubleValue>>(QualitiesBeforeReheatingName, "List of qualities where the algorithm has been stuck."));
112            Parameters.Add(new LookupParameter<DoubleValue>(LastAcceptedQualityName, "Quality of last accepted solution."));
113
114            Parameters.Add(new ValueLookupParameter<ITemperatureInitializer>(TemperatureInitializerName, "The operator that initilized the temperature."));
115            Parameters.Add(new LookupParameter<BoolValue>(TemperatureInitializedName, "True, if the temperature has already been initialized."));
116
117        }
118
119        public override IDeepCloneable Clone(Cloner cloner)
120        {
121            return new TemperatureController(this, cloner);
122        }
123
124        public override IOperation Apply()
125        {
126
127            if (!TemperatureInitializedParameter.ActualValue.Value)
128            {
129                return new OperationCollection
130                {
131                    ExecutionContext.CreateOperation(TemperatureInitializerParameter.ActualValue),
132                    base.Apply()
133                };
134            }
135            else
136            {
137                return new OperationCollection {
138                    ExecutionContext.CreateOperation(ReheatingOperatorParameter.ActualValue),
139                    base.Apply()
140                };
141            }
142        }
143    }
144}
Note: See TracBrowser for help on using the repository browser.