Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/30/17 07:50:37 (7 years ago)
Author:
jschiess
Message:

#1836 SA reheating strategies: Newest version of reheating

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/jschiess/HeuristicLab.Algorithms.SimulatedAnnealing/3.4/AcceptanceRatioReheatingOperator.cs

    r14555 r15001  
    3737        private const string IsAcceptedName = "IsAccepted";
    3838        private const string AcceptanceMemoryName = "AcceptanceMemory";
     39        private const string AverageAcceptanceRatioName = "AverageAcceptanceRatio";
    3940
    4041
     
    7374            get { return (ILookupParameter<IntValue>)Parameters[MaximumIterationsName]; }
    7475        }
    75         private ValueParameter<DoubleValue> UpperTemperatureParameter
    76         {
    77             get { return (ValueParameter<DoubleValue>)Parameters[UpperTemperatureName]; }
     76        private ValueLookupParameter<DoubleValue> UpperTemperatureParameter
     77        {
     78            get { return (ValueLookupParameter<DoubleValue>)Parameters[UpperTemperatureName]; }
    7879        }
    7980        private IConstrainedValueParameter<IDiscreteDoubleValueModifier> ReheatingOperatorParameter
     
    100101        {
    101102            get { return (ILookupParameter<ItemList<BoolValue>>)Parameters[AcceptanceMemoryName]; }
     103        }
     104        public ILookupParameter<DoubleValue> AverageAcceptanceRatioParameter
     105        {
     106            get { return (ILookupParameter<DoubleValue>)Parameters[AverageAcceptanceRatioName]; }
    102107        }
    103108
     
    118123            Parameters.Add(new LookupParameter<ItemList<BoolValue>>(AcceptanceMemoryName, "Memorizes the last N acceptance decisions."));
    119124            Parameters.Add(new LookupParameter<BoolValue>(CoolingName, "True when the temperature should be cooled, false otherwise."));
    120             Parameters.Add(new ValueParameter<DoubleValue>(UpperTemperatureName, "The upper bound of the temperature.", new DoubleValue(100d)));
     125            Parameters.Add(new ValueLookupParameter<DoubleValue>(UpperTemperatureName, "The upper bound of the temperature.", "InitialTemperature"));
    121126            Parameters.Add(new ConstrainedValueParameter<IDiscreteDoubleValueModifier>(ReheatingOperatorName, "The operator that reheats the temperature."));
    122             Parameters.Add(new ValueParameter<DoubleRange>(ThresholdName, "The threshold controls the temperature. If the average ratio of accepted moves goes below the start of the range the temperature is heated. If the the average ratio of accepted moves goes beyond the end of the range the temperature is cooled again.", new DoubleRange(0.2, 0.1)));
     127            Parameters.Add(new ValueParameter<DoubleRange>(ThresholdName, "The threshold controls the temperature. If the average ratio of accepted moves goes below the start of the range the temperature is heated. If the the average ratio of accepted moves goes beyond the end of the range the temperature is cooled again.", new DoubleRange(0.01, 0.1)));
    123128            Parameters.Add(new ValueParameter<IntValue>(MemorySizeName, "The maximum size of the acceptance memory.", new IntValue(100)));
    124 
     129            Parameters.Add(new LookupParameter<DoubleValue>(AverageAcceptanceRatioName, "Average acceptance over full acceptance memory."));
    125130            #endregion
    126131
     
    155160                op.StartValueParameter.ActualName = StartTemperatureName;
    156161                op.StartValueParameter.Hidden = true;
    157                 op.EndValueParameter.ActualName = UpperTemperatureName;
    158                 op.EndValueParameter.Value = UpperTemperatureParameter.Value;
     162                op.EndValueParameter.ActualName = EndTemperatureName;
    159163                op.EndValueParameter.Hidden = true;
    160164            }
     
    163167        public override IOperation Apply()
    164168        {
    165 
     169            var isAccepted = IsAcceptedParameter.ActualValue;
    166170            var acceptances = AcceptanceMemoryParameter.ActualValue;
    167171            var cooling = CoolingParameter.ActualValue.Value;
    168 
    169             acceptances.Add(IsAcceptedParameter.ActualValue);
    170 
    171             if (acceptances.Count > MemorySizeParameter.Value.Value) acceptances.RemoveAt(0);
    172 
    173             var ratioStart = ThresholdParameter.Value.Start;
    174             var ratioEnd = ThresholdParameter.Value.End;
    175             var ratio = acceptances.Average(x => x.Value ? 1.0 : 0.0);
    176 
    177            
    178             if (!cooling && ratio >= ratioEnd)
     172            var ratioAmount = AverageAcceptanceRatioParameter.ActualValue;
     173
     174            acceptances.Add(isAccepted);
     175
     176            ratioAmount.Value += isAccepted.Value ? 1 : 0;
     177
     178
     179            if (acceptances.Count > MemorySizeParameter.Value.Value) {
     180                ratioAmount.Value -= acceptances.ElementAt(0).Value ? 1 : 0;
     181                acceptances.RemoveAt(0);
     182            }
     183
     184            // only reheat when at least MemorySizeParameter.Value iterations have passed
     185            if (acceptances.Count == MemorySizeParameter.Value.Value)
    179186            {
    180                 // if we are heating, but should be cooling
    181                 cooling = true;
    182                 TemperatureStartIndexParameter.ActualValue.Value = Math.Max(0, IterationsParameter.ActualValue.Value - 1);
    183                 StartTemperatureParameter.ActualValue.Value = TemperatureParameter.ActualValue.Value;
    184                 EndTemperatureParameter.ActualValue.Value = LowerTemperatureParameter.ActualValue.Value;
    185             }
    186             else if (cooling && ratio <= ratioStart)
    187             {
    188                 // if we are cooling but should be heating
    189                 cooling = false;
    190                 TemperatureStartIndexParameter.ActualValue.Value = Math.Max(0, IterationsParameter.ActualValue.Value - 1);
    191                 StartTemperatureParameter.ActualValue.Value = TemperatureParameter.ActualValue.Value;
    192                 EndTemperatureParameter.ActualValue.Value = UpperTemperatureParameter.Value.Value;
    193             }
    194 
    195             CoolingParameter.ActualValue.Value = cooling;
    196 
     187                var ratio = ratioAmount.Value / MemorySizeParameter.Value.Value;
     188                var ratioStart = ThresholdParameter.Value.Start;
     189                var ratioEnd = ThresholdParameter.Value.End;
     190
     191                if (!cooling && ratio >= ratioEnd)
     192                {
     193                    // if we are heating, but should be cooling
     194                    cooling = true;
     195                    TemperatureStartIndexParameter.ActualValue.Value = Math.Max(0, IterationsParameter.ActualValue.Value - 1);
     196                    StartTemperatureParameter.ActualValue.Value = TemperatureParameter.ActualValue.Value;
     197                    EndTemperatureParameter.ActualValue.Value = LowerTemperatureParameter.ActualValue.Value;
     198                }
     199                else if (cooling && ratio <= ratioStart)
     200                {
     201                    // if we are cooling but should be heating
     202                    cooling = false;
     203                    TemperatureStartIndexParameter.ActualValue.Value = Math.Max(0, IterationsParameter.ActualValue.Value - 1);
     204                    StartTemperatureParameter.ActualValue.Value = TemperatureParameter.ActualValue.Value;
     205                    EndTemperatureParameter.ActualValue.Value = UpperTemperatureParameter.ActualValue.Value;
     206                }
     207
     208                CoolingParameter.ActualValue.Value = cooling;
     209            }
    197210            return cooling ? Cool() : Heat();
    198211        }
Note: See TracChangeset for help on using the changeset viewer.