Main Content

simulannealbnd

Find minimum of function using simulated annealing algorithm

Description

例子

X= simulannealbnd (Fun,,,,X0F一世nds a local minimum,X,到函数句柄Fun计算目标函数的值。X0是模拟退火算法的初始点,即真实向量。

笔记

Passing Extra Parametersexplains how to pass extra parameters to the objective function, if necessary.

例子

X= simulannealbnd (Fun,,,,X0,,,,lb,,,,ub在设计变量上定义了一组下层和上限X,,,,so that the solution is always in the rangelbXub。如果X(i)一世s unbounded below, setlb(i) = -Inf, 而如果X(i)在上面无限,设置ub(i) = Inf

例子

X= simulannealbnd (Fun,,,,X0,,,,lb,,,,ub,,,,optionsminimizes with the optimization options specified inoptions。创造optionsusing最佳选择。如果no bounds exist, setlb = []and/orub = []

X= simulannealbnd (problem找到最小problem,,,,a structure described inproblem

[[X,,,,FVAL] = simulannealbnd(___,,,,为了any syntax, returns the value of the objective functionFunat the solutionX

例子

[[X,,,,FVAL,,,,出口,,,,输出] = simulannealbnd(___additionally returns a value出口that describes the exit condition ofsimulannealbnd和一个结构输出有关优化过程的信息。

Examples

全部收缩

最小化De Jong的第五个功能,这是许多局部最小值的二维函数。

Plot De Jong's fifth function.

dejong5fcn

图包含一个轴对象。轴对象包含2个类型表面的对象,轮廓。

Minimize De Jong's fifth function usingsimulannealbndstarting from the point[0,0]

fun = @dejong5fcn;x0 = [0 0];x = simulanealbnd(娱乐,x0)
优化终止:最佳功能值的更改小于options.functionTolerance。
X=1×2-32.0285 -0.1280

simulannealbndalgorithm uses the MATLAB® random number stream, so you might obtain a different result.

Minimize De Jong’s fifth function within a bounded region.

Plot De Jong's fifth function.

dejong5fcn

图包含一个轴对象。轴对象包含2个类型表面的对象,轮廓。

开始simulannealbndstarting 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

simulannealbndalgorithm uses the MATLAB® random number stream, so you might obtain a different result.

Observe the progress ofsimulannealbndby setting options to use some plot functions.

设置模拟退火选项,以使用多个图功能。

options = optimoptions('simulannealbnd',,,,“ plotfcns”,,,,。。。{@saplotbestx,@saplotbestf,@saplotx,@saplotf});

开始simulannealbndstarting 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)

图模拟退火包含4轴对象。Axes object 1 with title Best point contains an object of type bar. Axes object 2 with title Best Function Value: 1.99203 contains an object of type line. Axes object 3 with title Current Point contains an object of type bar. Axes object 4 with title Current Function Value: 1.99203 contains an object of type line.

优化终止:最佳功能值的更改小于options.functionTolerance。
X=1×2-15.9790 -31.9593

Obtain all the outputs of a simulated annealing minimization.

Plot De Jong's fifth function.

dejong5fcn

图包含一个轴对象。轴对象包含2个类型表面的对象,轮廓。

开始simulannealbndstarting 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

simulannealbndalgorithm uses the MATLAB® random number stream, so you might obtain a different result.

输入参数

全部收缩

函数要最小化,指定为函数句柄或功能名称。Fun一世s a function that accepts a vectorXand 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

Funcan 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

Initial point, specified as a real vector.simulannealbnduses the number of elements inX0to determine the number of variables thatFun接受。

Example:X0=[[1,,,,2,3,4]

Data Types:double

下限,,,,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

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

优化选项,指定为返回的对象最佳选择or a structure. For details, see模拟退火选项

最佳选择隐藏列出的选项一世talics; see最佳选择的选项

{}denotes the default value. See option details in模拟退火选项

Option Description

AcceptanceFcn

Function the algorithm uses to determine if a new point is accepted. Specify as'Accentancesa'or a function handle.

功能处理|{'Accentancesa'}

退火FCN

函数算法用于生成新点。指定为内置退火功能或功能句柄的名称。

功能处理|Function name |“退火螺栓”|{'nealingfast'}

数据类型

决策变量类型

'custom'|{'双倍的'}

Display

Level of display

'off'|'iTer'|'diagnose'|{'final'}

DisplayInterval

Interval for iterative display

Positive integer |{10}

函数授体

功能值的终止公差

For an options structure, useTolFun

Positive scalar |{1E-6}

HybridFcn

Automatically runHybridFcn(另一个优化函数)在求解器的迭代末尾或结束时。指定为名称或函数句柄。

何时使用混合功能

'fminsearch' | 'patternsearch' | 'fminunc' | 'fmincon' | {[]}

or

1-by-2 cell array |{@solver, hybridoptions},,,,wheresolver = fminsearch,,,,patternsearch,,,,Fminunc,,,,orFmincon{[]}

HybridInterval

Interval (if not'结尾'or'never'HybridFcn一世s called

Positive integer |'never'|{'结尾'}

初始效果

Initial value of temperature

Positive scalar | positive vector |{100}

maxfunction evaluations

最大数量的目标函数tion evaluations allowed

For an options structure, useMaxFunEvals

Positive integer |{3000*numberOfVariables}

最大值

Maximum number of iterations allowed

For an options structure, useMaxIter

Positive integer |{inf}

MaxStallIterations

Number of iterations over which average change in fitness function value at current point is less thanoptions.functionTolerance

For an options structure, useStalliterlimit

Positive integer |{500*numberOfVariables}

MaxTime

该算法在运行后停止MaxTimeseconds

For an options structure, use时限

Positive scalar |{inf}

ObjectiveLimit

所需的最小目标函数值

Scalar |{-Inf}

OutputFcn

函数获取迭代数据,可以在运行时更改选项

For an options structure, useOutputFcns

功能处理|函数手柄的单元格数组|{[]}

plotfcn

迭代期间调用的情节功能

For an options structure, useplotfcns

功能处理|built-in plot function name | cell array of function handles | cell array of built-in plot function names |'saplotbestf'|'saplotbestx'|'saplotf'|“ saplotstopping'|'saplottemperature'|{[]}

PlotInterval

Plot functions are called at every interval

Positive integer |{1}

ReannealInterval

Reannealing interval

Positive integer |{100}

TemperatureFcn

Function used to update temperature schedule

功能处理|内置温度功能名称|“温度螺栓”|“温度快”|{'deveripexp'}

Example:options = optimoptions(@simulannealbnd,'Maxiterations',150)

Data Types:结构

问题结构,指定为具有以下字段的结构:

  • objective- 目标功能

  • X0-开始一世ng point

  • lb-Lower bound forX

  • ub-Upper bound forX

  • solver-'simulannealbnd'

  • options-Options created with最佳选择或选项结构

  • rngstate- 可选字段重置随机数生成器的状态

笔记

problemmust have all the fields as specified above.

Data Types:结构

Output Arguments

全部收缩

Solution, returned as a real vector. The size ofX一世s the same as the size ofX0。Typically,X一世s a local solution to the problem when出口是积极的。

Objective function value at the solution, returned as a real number. Generally,FVAL=Fun(x)

Reasonsimulannealbnd停下来,返回为整数。

Exit Flag Meaning
1

目标函数价值的平均变化options.MaxStallIterations迭代少于options.functionTolerance

5

Objective function value is less thanoptions.objectivelimit

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, 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随机数生成器的状态,就在算法启动之前。您可以在rngstateto reproduce the output ofsimulannealbnd。看Reproduce Your Results

Alternative Functionality

App

OptimizeLive Editor task provides a visual interface forsimulannealbnd

版本历史记录

在R2007A中引入