simulannealbnd
Find minimum of function using simulated annealing algorithm
Syntax
Description
finds
a local minimum, x
= simulannealbnd(fun
,x0
)x
, to the function handle fun
that
computes the values of the objective function. x0
is
an initial point for the simulated annealing algorithm, a real vector.
Note
Passing Extra Parameters explains how to pass extra parameters to the objective function, if necessary.
Examples
Minimize a Function with Many Local Minima
Minimize De Jong's fifth function, a two-dimensional function with many local minima. This function is available when you run this example.
Plot De Jong's fifth function.
dejong5fcn
Minimize De Jong's fifth function using simulannealbnd
starting from the point [0,0]
.
fun = @dejong5fcn; x0 = [0 0]; x = simulannealbnd(fun,x0)
simulannealbnd stopped because the change in best function value is less than options.FunctionTolerance.
x = 1×2
-32.0285 -0.1280
The simulannealbnd
algorithm uses the MATLAB® random number stream, so you might obtain a different result.
Minimize Subject to Bounds
Minimize De Jong’s fifth function within a bounded region. This function is available when you run this example.
Plot De Jong's fifth function.
dejong5fcn
Start simulannealbnd
starting at the point [0,0]
, and set lower bounds of -64 and upper bounds of 64 on each component.
fun = @dejong5fcn; x0 = [0 0]; lb = [-64 -64]; ub = [64 64]; x = simulannealbnd(fun,x0,lb,ub)
simulannealbnd stopped because the change in best function value is less than options.FunctionTolerance.
x = 1×2
-15.9790 -31.9593
The simulannealbnd
algorithm uses the MATLAB® random number stream, so you might obtain a different result.
Minimize Using Nondefault Options
Observe the progress of simulannealbnd
by setting options to use some plot functions.
Set simulated annealing options to use several plot functions.
options = optimoptions('simulannealbnd','PlotFcns',... {@saplotbestx,@saplotbestf,@saplotx,@saplotf});
Start simulannealbnd
starting at the point [0,0]
, and set lower bounds of -64 and upper bounds of 64 on each component. Minimize the dejong5fcn
, which is available when you run this example.
rng default % For reproducibility fun = @dejong5fcn; x0 = [0,0]; lb = [-64,-64]; ub = [64,64]; x = simulannealbnd(fun,x0,lb,ub,options)
simulannealbnd stopped because the change in best function value is less than options.FunctionTolerance.
x = 1×2
-15.9790 -31.9593
Obtain All Outputs
Obtain all the outputs of a simulated annealing minimization.
Plot De Jong's fifth function, which is available when you run this example.
dejong5fcn
Start simulannealbnd
starting at the point [0,0]
, and set lower bounds of -64 and upper bounds of 64 on each component.
fun = @dejong5fcn; x0 = [0,0]; lb = [-64,-64]; ub = [64,64]; [x,fval,exitflag,output] = simulannealbnd(fun,x0,lb,ub)
simulannealbnd stopped because the change in best function value is less than options.FunctionTolerance.
x = 1×2
-15.9790 -31.9593
fval = 1.9920
exitflag = 1
output = struct with fields:
iterations: 1762
funccount: 1779
message: 'simulannealbnd stopped because the change in best function value is less than options.FunctionTolerance.'
rngstate: [1x1 struct]
problemtype: 'boundconstraints'
temperature: [2x1 double]
totaltime: 0.9367
The simulannealbnd
algorithm uses the MATLAB® random number stream, so you might obtain a different result.
Input Arguments
fun
— Function to be minimized
function handle | function name
Function to be minimized, specified as a function handle or
function name.fun
is a function that accepts a
vector x
and returns a real scalar f
,
the objective function evaluated at x
.
fun
can be specified as a function handle
for a file:
x = simulannealbnd(@myfun,x0)
where myfun
is a MATLAB® function such
as
function f = myfun(x) f = ... % Compute function value at x
fun
can also be a function handle for an
anonymous function:
x = simulannealbnd(@(x)norm(x)^2,x0,lb,ub);
Example: fun = @(x)sin(x(1))*cos(x(2))
Data Types: char
| function_handle
| string
x0
— Initial point
real vector
Initial point, specified as a real vector. simulannealbnd
uses
the number of elements in x0
to determine the number
of variables that fun
accepts.
Example: x0 = [1,2,3,4]
Data Types: double
lb
— Lower bounds
real vector | real array
Lower bounds, specified as a real vector or real array. If the
number of elements in x0
is equal to that of lb
,
then lb
specifies that
x(i) >= lb(i)
for all i
.
If numel(lb) < numel(x0)
, then lb
specifies
that
x(i) >= lb(i)
for 1 <=
i <= numel(lb)
.
In this case, solvers issue a warning.
Example: To specify that all control variables are positive, lb
= zeros(size(x0))
Data Types: double
ub
— Upper bounds
real vector | real array
Upper bounds, specified as a real vector or real array. If the
number of elements in x0
is equal to that of ub
,
then ub
specifies that
x(i) <= ub(i)
for all i
.
If numel(ub) < numel(x0)
, then ub
specifies
that
x(i) <= ub(i)
for 1 <=
i <= numel(ub)
.
In this case, solvers issue a warning.
Example: To specify that all control variables are less than
one, ub = ones(size(x0))
Data Types: double
options
— Optimization options
object returned by optimoptions
| structure
Optimization options, specified as an object returned by optimoptions
or a
structure. For details, see Simulated Annealing Options.
optimoptions
hides the options listed in italics;
see Options that optimoptions Hides.
{}
denotes the default value. See option details in
Simulated Annealing Options.
Option | Description | Values |
---|---|---|
| Function the algorithm uses to determine if a new point is accepted. Specify as
| Function handle | |
| Function the algorithm uses to generate new points. Specify as a name of a built-in annealing function or a function handle. | Function handle | function name | |
| Type of decision variable |
|
| Level of display |
|
DisplayInterval | Interval for iterative display | Positive integer | |
FunctionTolerance | Termination tolerance on function value For an options structure, use
| Nonnegative scalar | |
| Automatically run |
or 1-by-2 cell array |
|
HybridInterval | Interval (if not | Positive integer | |
| Initial value of temperature | Nonnegative scalar | positive vector | |
| Maximum number of objective function evaluations allowed For an options
structure, use | Nonnegative integer | |
| Maximum number of iterations allowed For an options structure, use
| Nonnegative integer | |
| Number of iterations over which average change in fitness function value at current
point is less than
For an options
structure, use | Nonnegative integer | |
| The algorithm stops after running for For an options structure, use
| Nonnegative scalar | |
| Minimum objective function value desired | Scalar | |
| Function(s) get(s) iterative data and can change options at run time For an
options structure, use | Function handle | cell array of function handles |
|
| Plot function(s) called during iterations For an options structure, use
| Function handle | built-in plot function name | cell array of function handles | cell
array of built-in plot function names | |
PlotInterval | Plot functions are called at every interval | Positive integer | |
| Reannealing interval | Nonnegative integer | |
| Function used to update temperature schedule | Function handle | built-in temperature function name |
|
Example: options = optimoptions(@simulannealbnd,'MaxIterations',150)
Data Types: struct
problem
— Problem structure
structure
Problem structure, specified as a structure with the following fields:
objective
— Objective functionx0
— Starting pointlb
— Lower bound forx
ub
— Upper bound forx
solver
—'simulannealbnd'
options
— Options created withoptimoptions
or an options structurerngstate
— Optional field to reset the state of the random number generator
Note
problem
must have all the fields as specified
above.
Data Types: struct
Output Arguments
fval
— Objective function value at the solution
real number
Objective function value at the solution, returned as a real
number. Generally, fval
= fun(x)
.
exitflag
— Reason simulannealbnd
stopped
integer
Reason simulannealbnd
stopped, returned
as an integer.
Exit Flag | Meaning |
---|---|
1 |
Average change in the value of the objective function
over |
5 | Objective function value is less than
|
0 |
Maximum number of function evaluations or iterations reached. |
-1 |
Optimization terminated by an output function or plot function. |
-2 |
No feasible point found. |
-5 |
Time limit exceeded. |
output
— Information about the optimization process
structure
Information about the optimization process, returned as a structure with fields:
problemtype
— Type of problem: unconstrained or bound constrained.iterations
— The number of iterations computed.funccount
— The number of evaluations of the objective function.message
— The reason the algorithm terminated.temperature
— Temperature when the solver terminated.totaltime
— Total time for the solver to run.rngstate
— State of the MATLAB random number generator, just before the algorithm started. You can use the values inrngstate
to reproduce the output ofsimulannealbnd
. See Reproduce Your Results.
Alternative Functionality
App
The Optimize Live Editor task provides a visual interface for simulannealbnd
.
Version History
Introduced in R2007a
See Also
ga
| optimoptions
| patternsearch
| Optimize
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)