#region License Information
/* HeuristicLab
* Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Linq;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Operators;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Optimization;
namespace HeuristicLab.Algorithms.SimulatedAnnealing
{
[Item("TemperatureController", "Responsible to first initialize the temperature and then control the temperature.")]
[StorableClass]
public class TemperatureController : SingleSuccessorOperator
{
#region Strings
private const string ReheatingOperatorName = "ReheatingOperator";
private const string AnnealingOperatorName = "AnnealingOperator";
private const string MaximumIterationsName = "MaximumIterations";
private const string InitialTemperatureName = "InitialTemperature";
private const string LowerTemperatureName = "LowerTemperature";
private const string IterationsName = "Iterations";
private const string TemperatureStartIndexName = "TemperatureStartIndex";
private const string CoolingName = "Cooling";
private const string StartTemperatureName = "StartTemperature";
private const string EndTemperatureName = "EndTemperature";
private const string TemperatureName = "Temperature";
private const string IsAcceptedName = "IsAccepted";
private const string ConsecutiveRejectedSolutionsCountName = "ConsecutiveRejectedSolutions";
private const string AverageAcceptanceRatioName = "AverageAcceptanceRatio";
private const string AcceptanceMemoryName = "AcceptanceMemory";
private const string LastQualityName = "LastQuality";
private const string UphillMovesMemoryName = "UphillMovesMemory";
private const string MaximizationName = "Maximization";
private const string MoveQualityName = "MoveQuality";
private const string CurrentRandomWalkStepName = "CurrentRandomWalkStep";
private const string LastAcceptedQualityName = "LastAcceptedQuality";
private const string TemperatureInitializerName = "TemperatureInitializer";
private const string TemperatureInitializedName = "TemperatureInitialized";
#endregion
#region Parameter Properties
public IValueLookupParameter ReheatingOperatorParameter
{
get { return (IValueLookupParameter)Parameters[ReheatingOperatorName]; }
}
public IValueLookupParameter TemperatureInitializerParameter
{
get { return (IValueLookupParameter)Parameters[TemperatureInitializerName]; }
}
public ILookupParameter TemperatureInitializedParameter
{
get { return (ILookupParameter)Parameters[TemperatureInitializedName]; }
}
#endregion
[StorableConstructor]
protected TemperatureController(bool deserializing) : base(deserializing) { }
protected TemperatureController(TemperatureController original, Cloner cloner) : base(original, cloner) { }
public TemperatureController()
: base()
{
Parameters.Add(new LookupParameter(TemperatureName, "The current temperature."));
Parameters.Add(new ValueLookupParameter(LowerTemperatureName, "The lower bound of the temperature."));
Parameters.Add(new LookupParameter(IterationsName, "The number of iterations."));
Parameters.Add(new ValueLookupParameter(MaximumIterationsName, "The maximum number of iterations which should be processed."));
Parameters.Add(new ValueLookupParameter(MaximizationName, "True if the problem is a maximization problem, otherwise false."));
Parameters.Add(new ValueLookupParameter(AnnealingOperatorName, "The operator that cools the temperature."));
Parameters.Add(new ValueLookupParameter(ReheatingOperatorName, "The operator that reheats the temperature if necessary."));
Parameters.Add(new LookupParameter(TemperatureStartIndexName, "The index where the annealing or heating was last changed."));
Parameters.Add(new LookupParameter(CoolingName, "True when the temperature should be cooled, false otherwise."));
Parameters.Add(new LookupParameter(StartTemperatureName, "The temperature from which cooling or reheating should occur."));
Parameters.Add(new LookupParameter(EndTemperatureName, "The temperature to which should be cooled or heated."));
Parameters.Add(new LookupParameter(IsAcceptedName, "Whether the move was accepted or not."));
Parameters.Add(new LookupParameter>(AcceptanceMemoryName, "Memorizes the last N acceptance decisions."));
Parameters.Add(new LookupParameter(InitialTemperatureName, "The initial temperature."));
Parameters.Add(new LookupParameter>(UphillMovesMemoryName, "Memorizes the last 100 uphill moves."));
Parameters.Add(new LookupParameter(MoveQualityName, "The value which represents the quality of a move."));
Parameters.Add(new LookupParameter(LastQualityName, "The value which represents the quality of the last move."));
Parameters.Add(new LookupParameter(ConsecutiveRejectedSolutionsCountName, "Amount of consecutive rejected solutions."));
Parameters.Add(new LookupParameter(AverageAcceptanceRatioName, "Average acceptance over full acceptance memory."));
Parameters.Add(new LookupParameter(CurrentRandomWalkStepName, "Current random walk step."));
Parameters.Add(new LookupParameter(LastAcceptedQualityName, "Quality of last accepted solution."));
Parameters.Add(new ValueLookupParameter(TemperatureInitializerName, "The operator that initilized the temperature."));
Parameters.Add(new LookupParameter(TemperatureInitializedName, "True, if the temperature has already been initialized."));
}
public override IDeepCloneable Clone(Cloner cloner)
{
return new TemperatureController(this, cloner);
}
public override IOperation Apply()
{
if (!TemperatureInitializedParameter.ActualValue.Value)
{
return new OperationCollection
{
ExecutionContext.CreateOperation(TemperatureInitializerParameter.ActualValue),
base.Apply()
};
}
else
{
return new OperationCollection {
ExecutionContext.CreateOperation(ReheatingOperatorParameter.ActualValue),
base.Apply()
};
}
}
}
}