1 | using HeuristicLab.Common;
|
---|
2 | using HeuristicLab.Core;
|
---|
3 | using HeuristicLab.Data;
|
---|
4 | using HeuristicLab.Operators;
|
---|
5 | using HeuristicLab.Parameters;
|
---|
6 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
7 | using System;
|
---|
8 | using System.Collections.Generic;
|
---|
9 | using System.Linq;
|
---|
10 | using System.Text;
|
---|
11 | using System.Threading.Tasks;
|
---|
12 |
|
---|
13 | namespace HeuristicLab.Algorithms.SimulatedAnnealing
|
---|
14 | {
|
---|
15 | [Item("BasicTemperatureInitializer", "Sets the initial temperature to a fixed value.")]
|
---|
16 | [StorableClass]
|
---|
17 | public class BasicTemperatureInitializer : SingleSuccessorOperator, ITemperatureInitializer
|
---|
18 | {
|
---|
19 | #region Strings
|
---|
20 | private const string InitialTemperatureName = "InitialTemperature";
|
---|
21 | private const string TemperatureInitializedName = "TemperatureInitialized";
|
---|
22 | private const string InitialTemperatureSetterName = "InitialTemperatureValue";
|
---|
23 | private const string StartTemperatureName = "StartTemperature";
|
---|
24 | private const string TemperatureStartIndexName = "TemperatureStartIndex";
|
---|
25 | private const string TemperatureName = "Temperature";
|
---|
26 | private const string IterationsName = "Iterations";
|
---|
27 | #endregion
|
---|
28 |
|
---|
29 | #region Properties
|
---|
30 | public ILookupParameter<DoubleValue> InitialTemperatureParameter
|
---|
31 | {
|
---|
32 | get { return (ILookupParameter<DoubleValue>)Parameters[InitialTemperatureName]; }
|
---|
33 | }
|
---|
34 | public ILookupParameter<BoolValue> TemperatureInitializedParameter
|
---|
35 | {
|
---|
36 | get { return (ILookupParameter<BoolValue>)Parameters[TemperatureInitializedName]; }
|
---|
37 | }
|
---|
38 | public IValueParameter<DoubleValue> InitialTemperatureSetterParameter
|
---|
39 | {
|
---|
40 | get { return (IValueParameter<DoubleValue>)Parameters[InitialTemperatureSetterName]; }
|
---|
41 | }
|
---|
42 | public ILookupParameter<DoubleValue> StartTemperatureParameter
|
---|
43 | {
|
---|
44 | get { return (ILookupParameter<DoubleValue>)Parameters[StartTemperatureName]; }
|
---|
45 | }
|
---|
46 | public ILookupParameter<IntValue> TemperatureStartIndexParameter
|
---|
47 | {
|
---|
48 | get { return (ILookupParameter<IntValue>)Parameters[TemperatureStartIndexName]; }
|
---|
49 | }
|
---|
50 | public ILookupParameter<DoubleValue> TemperatureParameter
|
---|
51 | {
|
---|
52 | get { return (ILookupParameter<DoubleValue>)Parameters[TemperatureName]; }
|
---|
53 | }
|
---|
54 | public ILookupParameter<IntValue> IterationsParameter
|
---|
55 | {
|
---|
56 | get { return (ILookupParameter<IntValue>)Parameters[IterationsName]; }
|
---|
57 | }
|
---|
58 |
|
---|
59 | #endregion
|
---|
60 |
|
---|
61 | public BasicTemperatureInitializer() : base()
|
---|
62 | {
|
---|
63 | Parameters.Add(new LookupParameter<DoubleValue>(InitialTemperatureName, "Temporary initial temperature field."));
|
---|
64 | Parameters.Add(new ValueParameter<DoubleValue>(InitialTemperatureSetterName, "Sets the initial temperature to this value", new DoubleValue(100)));
|
---|
65 | Parameters.Add(new LookupParameter<BoolValue>(TemperatureInitializedName, "True, if the temperature has already been initialized."));
|
---|
66 | Parameters.Add(new LookupParameter<DoubleValue>(StartTemperatureName, "The temperature from which cooling or reheating should occur."));
|
---|
67 | Parameters.Add(new LookupParameter<IntValue>(TemperatureStartIndexName, "The index where the annealing or heating was last changed."));
|
---|
68 | Parameters.Add(new LookupParameter<DoubleValue>(TemperatureName, "The current temperature."));
|
---|
69 | Parameters.Add(new LookupParameter<IntValue>(IterationsName, "The number of iterations."));
|
---|
70 | }
|
---|
71 |
|
---|
72 | [StorableConstructor]
|
---|
73 | protected BasicTemperatureInitializer(bool deserializing) : base(deserializing) { }
|
---|
74 | protected BasicTemperatureInitializer(BasicTemperatureInitializer original, Cloner cloner) : base(original, cloner) { }
|
---|
75 |
|
---|
76 |
|
---|
77 | public override IDeepCloneable Clone(Cloner cloner)
|
---|
78 | {
|
---|
79 | return new BasicTemperatureInitializer(this, cloner);
|
---|
80 | }
|
---|
81 |
|
---|
82 | public override IOperation Apply()
|
---|
83 | {
|
---|
84 | // set temperature to selected value
|
---|
85 | InitialTemperatureParameter.ActualValue.Value = InitialTemperatureSetterParameter.Value.Value;
|
---|
86 | TemperatureParameter.ActualValue.Value = InitialTemperatureSetterParameter.Value.Value;
|
---|
87 | TemperatureStartIndexParameter.ActualValue.Value = Math.Max(0, IterationsParameter.ActualValue.Value - 1);
|
---|
88 | StartTemperatureParameter.ActualValue.Value = TemperatureParameter.ActualValue.Value;
|
---|
89 |
|
---|
90 | // indicate that initial temperature is now set
|
---|
91 | TemperatureInitializedParameter.ActualValue.Value = true;
|
---|
92 |
|
---|
93 | return base.Apply();
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|