simulannealbnd
Find minimum of function using simulated annealing algorithm
句法
Description
F一世nds a local minimum,X
= simulannealbnd (Fun
,,,,X0
)X
,到函数句柄Fun
计算目标函数的值。X0
是模拟退火算法的初始点,即真实向量。
笔记
Passing Extra Parametersexplains how to pass extra parameters to the objective function, if necessary.
Examples
Minimize a Function with Many Local Minima
最小化De Jong的第五个功能,这是许多局部最小值的二维函数。
Plot De Jong's fifth function.
dejong5fcn
Minimize De Jong's fifth function usingsimulannealbnd
starting from the point[0,0]
。
fun = @dejong5fcn;x0 = [0 0];x = simulanealbnd(娱乐,x0)
优化终止:最佳功能值的更改小于options.functionTolerance。
X=1×2-32.0285 -0.1280
这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.
Plot De Jong's fifth function.
dejong5fcn
开始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 = simulanealbnd(fun,x0,lb,ub)
优化终止:最佳功能值的更改小于options.functionTolerance。
X=1×2-15.9790 -31.9593
这simulannealbnd
algorithm uses the MATLAB® random number stream, so you might obtain a different result.
Minimize Using Nondefault Options
Observe the progress ofsimulannealbnd
by setting options to use some plot functions.
设置模拟退火选项,以使用多个图功能。
options = optimoptions('simulannealbnd',,,,“ plotfcns”,,,,。。。{@saplotbestx,@saplotbestf,@saplotx,@saplotf});
开始simulannealbnd
starting at the point[0,0]
,,,,and set lower bounds of -64 and upper bounds of 64 on each component.
rngdefault% For reproducibilityfun = @dejong5fcn;x0 = [0,0];lb = [-64,-64];ub = [64,64];X= simulannealbnd (Fun,x0,lb,ub,options)
优化终止:最佳功能值的更改小于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.
dejong5fcn
开始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,输出] = simulanealbnd(fun,x0,lb,ub)
优化终止:最佳功能值的更改小于options.functionTolerance。
X=1×2-15.9790 -31.9593
FVAL=1。9920
出口= 1
输出=带有字段的结构:一世terations: 1762 funccount: 1779 message: 'Optimization terminated: change in best function value less than options.FunctionTolerance.' rngstate: [1x1 struct] problemtype: 'boundconstraints' temperature: [2x1 double] totaltime: 0.9163
这simulannealbnd
algorithm uses the MATLAB® random number stream, so you might obtain a different result.
输入参数
Fun
-Function to be minimized
功能句柄|Function name
函数要最小化,指定为函数句柄或功能名称。Fun
一世s a function that accepts a vectorX
and returns a real scalarF
,评估的目标函数X
。
Fun
可以指定为文件的函数句柄:
x = simulanealbnd(@myfun,x0)
wheremyfun
是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 inX0
to determine the number of variables thatFun
接受。
Example:X0=[[1,,,,2,3,4]
Data Types:double
lb
-下限
real vector|真正的数组
下限,,,,specified as a real vector or real array. If the number of elements inX0
等于lb
, 然后lb
指定
X(i) >= lb(i)
为了all一世
。
如果numel(lb) < numel(x0)
, 然后lb
指定
X(i) >= lb(i)
为了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|真正的数组
Upper bounds, specified as a real vector or real array. If the number of elements inX0
等于ub
, 然后ub
指定
X(i) <= ub(i)
为了all一世
。
如果numel(ub)
ub
指定
X(i) <= ub(i)
为了1<= i <= numel(ub)
。
In this case, solvers issue a warning.
Example:To specify that all control variables are less than one,ub =一个(size(x0))
Data Types:double
options
-优化选项
对象返回最佳选择
|结构ure
优化选项,指定为返回的对象最佳选择
or a structure. For details, see模拟退火选项。
最佳选择
隐藏列出的选项一世talics; see最佳选择的选项。
{}
denotes the default value. See option details in模拟退火选项。
Option | Description | 值 |
---|---|---|
|
Function the algorithm uses to determine if a new point is accepted. Specify as |
功能处理| |
|
函数算法用于生成新点。指定为内置退火功能或功能句柄的名称。 |
功能处理|Function name | |
|
决策变量类型 |
|
|
Level of display |
|
DisplayInterval |
Interval for iterative display |
Positive integer | |
函数授体 |
功能值的终止公差 For an options structure, use |
Positive scalar | |
|
Automatically run 看何时使用混合功能。 |
or 1-by-2 cell array | |
HybridInterval |
Interval (if not |
Positive integer | |
|
Initial value of temperature |
Positive scalar | positive vector | |
|
最大数量的目标函数tion evaluations allowed For an options structure, use |
Positive integer | |
|
Maximum number of iterations allowed For an options structure, use |
Positive integer | |
|
Number of iterations over which average change in fitness function value at current point is less than For an options structure, use |
Positive integer | |
|
该算法在运行后停止 For an options structure, use |
Positive scalar | |
|
所需的最小目标函数值 |
Scalar | |
|
函数获取迭代数据,可以在运行时更改选项 For an options structure, use |
功能处理|函数手柄的单元格数组| |
|
迭代期间调用的情节功能 For an options structure, use |
功能处理|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 |
Positive integer | |
|
Function used to update temperature schedule |
功能处理|内置温度功能名称| |
Example:options = optimoptions(@simulannealbnd,'Maxiterations',150)
Data Types:结构
problem
-Problem structure
结构ure
问题结构,指定为具有以下字段的结构:
objective
- 目标功能X0
-开始一世ng pointlb
-Lower bound forX
ub
-Upper bound forX
solver
-'simulannealbnd'
options
-Options created with最佳选择
或选项结构rngstate
- 可选字段重置随机数生成器的状态
笔记
problem
must have all the fields as specified above.
Data Types:结构
Output Arguments
FVAL
- 目标功能value at the solution
real number
Objective function value at the solution, returned as a real number. Generally,FVAL
=Fun(x)
。
出口
-Reasonsimulannealbnd
stopped
一世nteger
Reasonsimulannealbnd
停下来,返回为整数。
Exit Flag | Meaning |
---|---|
1 |
目标函数价值的平均变化 |
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 |
找不到可行的观点。 |
-5 |
Time limit exceeded. |
输出
-Information about the optimization process
结构ure
Information about the optimization process, returned as a structure with fields:
问题类型
- 问题类型:不受约束或约束。一世terations
- 计算的迭代次数。Funccount
-这number of evaluations of the objective function.信息
-这reason the algorithm terminated.temperature
- 求解器终止时温度。totaltime
-Total time for the solver to run.rngstate
- MATLAB随机数生成器的状态,就在算法启动之前。您可以在rngstate
to reproduce the output ofsimulannealbnd
。看Reproduce Your Results。
Alternative Functionality
App
这OptimizeLive Editor task provides a visual interface forsimulannealbnd
。
版本历史记录
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
您单击了与此MATLAB命令相对应的链接:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择一个网站
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
选择中国网站(中文或英语)以获得最佳场地性能。其他Mathworks乡村网站未针对您所在的访问进行优化。
美洲
- América Latina(Español)
- 加拿大(English)
- 美国(English)
Europe
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- 葡萄牙(English)
- Sweden(English)
- 瑞士
- United Kingdom(English)