Simulated Annealing Algorthim
Simulated Annealing Algorthim
Simulated Annealing Algorthim
Simulated annealing is a method for solving unconstrained and bound-constrained optimization problems. The
method models the physical process of heating a material and then slowly lowering the temperature to decrease
defects, thus minimizing the system energy.
At each iteration of the simulated annealing algorithm, a new point is randomly generated. The distance of the
new point from the current point, or the extent of the search, is based on a probability distribution with a scale
proportional to the temperature. The algorithm accepts all new points that lower the objective, but also, with a
certain probability, points that raise the objective. By accepting points that raise the objective, the algorithm
avoids being trapped in local minima, and is able to explore globally for more possible solutions. An annealing
schedule is selected to systematically decrease the temperature as the algorithm proceeds. As the temperature
decreases, the algorithm reduces the extent of its search to converge to a minimum.
Temperature
The temperature is a parameter in simulated annealing that affects two aspects of the algorithm:
The distance of a trial point from the current point (See Outline of the Algorithm, Step 1.)
The probability of accepting a trial point with higher objective function value (See Outline of the Algorithm, Step
2.)
Temperature can be a vector with different values for each component of the current point. Typically, the initial
temperature is a scalar.
Temperature decreases gradually as the algorithm proceeds. You can specify the initial temperature as a positive
scalar or vector in the InitialTemperature option. You can specify the temperature as a function of iteration
number as a function handle in the TemperatureFcn option. The temperature is a function of the Annealing
Parameter, which is a proxy for the iteration number. The slower the rate of temperature decrease, the better the
chances are of finding an optimal solution, but the longer the run time. For a list of built-in temperature functions
and the syntax of a custom temperature function, see Temperature Options.
Annealing Parameter
The annealing parameter is a proxy for the iteration number. The algorithm can raise temperature by setting the
annealing parameter to a lower value than the current iteration. (SeeReannealing.) You can specify the
temperature schedule as a function handle with the TemperatureFcn option.
Reannealing
Annealing is the technique of closely controlling the temperature when cooling a material to ensure that it
reaches an optimal state. Reannealing raises the temperature after the algorithm accepts a certain number of
new points, and starts the search again at the higher temperature. Reannealing avoids the algorithm getting
caught at local minima. Specify the reannealing schedule with the ReannealInterval option.
@temperaturefast — T = T / k. 0
@temperatureboltz — T = T / log(k). 0
@myfun — Custom temperature function, myfun. For custom temperature function syntax,
see Temperature Options.
4. simulannealbnd reanneals after it accepts ReannealInterval points. Reannealing sets the
annealing parameters to lower values than the iteration number, thus raising the
temperature in each dimension. The annealing parameters depend on the values of
estimated gradients of the objective function in each dimension. The basic formula is
( )
( )
ki=log ,
T0Timaxj sj si
where
k = annealing parameter for component i.
i
simulannealbnd safeguards the annealing parameter values against Inf and other
improper values.
5. The algorithm stops when the average change in the objective function is small relative
to FunctionTolerance, or when it reaches any other stopping criterion. See Stopping
Conditions for the Algorithm.
For more information on the algorithm, see Ingber [1].
Stopping Conditions for the Algorithm
The simulated annealing algorithm uses the following conditions to determine when to stop:
FunctionTolerance — The algorithm runs until the average change in value of the objective
function in StallIterLim iterations is less than the value of FunctionTolerance. The default
value is 1e-6.
MaxIterations — The algorithm stops when the number of iterations exceeds this maximum
number of iterations. You can specify the maximum number of iterations as a positive integer
orInf. The default value is Inf.
MaxFunctionEvaluations specifies the maximum number of evaluations of the objective
function. The algorithm stops if the number of function evaluations exceeds the value
ofMaxFunctionEvaluations. The default value is 3000*numberofvariables.
MaxTime specifies the maximum time in seconds the algorithm runs before stopping. The
default value is Inf.
ObjectiveLimit — The algorithm stops when the best objective function value is less than or
equal to the value of ObjectiveLimit. The default value is -Inf.
Bibliography
[1] Ingber, L. Adaptive simulated annealing (ASA): Lessons learned. Invited paper to a
special issue of the Polish Journal Control and Cybernetics on "Simulated Annealing
Applied to Combinatorial Optimization." 1995. Available
from http://www.ingber.com/asa96_lessons.ps.gz
See Set Options for simulannealbnd at the Command Line for examples.
Each option in this section is listed by its field name in the options structure. For
example, InitialTemperature refers to the corresponding field of the options structure.
Plot Options
Plot options enable you to plot data from the simulated annealing solver while it is running.
PlotInterval specifies the number of iterations between consecutive calls to the plot
function.
To display a plot when calling simulannealbnd from the command line, set the PlotFcn field
of options to be a function handle to the plot function. You can specify any of the following
plots:
@saplotbestf plots the best objective function value.
@saplotbestx plots the current best point.
@saplotf plots the current function value.
@saplotx plots the current point.
@saplotstopping plots stopping criteria levels.
@saplottemperature plots the temperature at each iteration.
@myfun plots a custom plot function, where myfun is the name of your function. See Structure
of the Plot Functions for a description of the syntax.
For example, to display the best objective plot, set options as follows
options = optimoptions(@simulannealbnd,'PlotFcn',@saplotbestf);
where @plotfun1, @plotfun2, and so on are function handles to the plot functions.
If you specify more than one plot function, all plots appear as subplots in the same window.
Right-click any subplot to obtain a larger version in a separate figure window.
Structure of the Plot Functions
Algorithm Settings
Algorithm settings define algorithmic specific parameters used in generating new points at
each iteration.
Parameters that can be specified for simulannealbnd are:
DataType — Type of data to use in the objective function. Choices:
o 'double' (default) — A vector of type double.
o 'custom' — Any other data type. You must provide a 'custom' annealing function. You
cannot use a hybrid function.
AnnealingFcn — Function used to generate new points for the next iteration. The choices are:
o @annealingfast — The step has length temperature, with direction uniformly at random. This
is the default.
o @annealingboltz — The step has length square root of temperature, with direction uniformly
at random.
o @myfun — Uses a custom annealing algorithm, myfun. The syntax is:
newx = myfun(optimValues,problem)
where optimValues is a structure described in Structure of the Output Function, and problem is a
structure containing the following information:
where optimValues is a structure described in Structure of the Output Function, newx is the point
being evaluated for acceptance, and newfval is the objective function at newx.acceptpoint is a
Boolean, with value true to accept newx, and false to reject newx.
options = optimoptions(@simulannealbnd,options,'HybridFcn',
{@fminunc,hybridopts});
hybridopts must exist before you set options.
To see a template that you can use to write your own output functions, enter
edit saoutputfcntemplate