主要内容

optimvalues

为优化问题创建值

描述

example

瓦尔= optimvalues(概率,dataName1,dataval1,...)creates an优化价值object for the problem概率。通过使用名称值参数,指定所有变量名称及其关联的值以及可选的目标或约束值。例如,指定x从1到99的奇数值,

瓦尔= optimvalues(概率,x=1:2:99);

利用瓦尔as an initial point or initial population for概率

例子

全部收缩

为创建初始点ga(genetic algorithm solver) in the problem-based approach, create an优化价值object usingoptimvalues

用Rosenbrock的功能作为适应性(目标)函数创建针对2D问题的优化变量。

x = optimvar("x",下部= -5,upperbound = 5);y = optimvar("y",下部= -5,upperbound = 5);rosenbrock =(10*(y -x。^2))。^2 +(1 -x)。^2;prob = optimproblem(Objective = RosenBrock);

创造100 random 2-D points within the bounds. The points must be row vectors.

RNGdefault%可再现性xval = -5 + 10*rand(1,100);yval = -5 + 10*rand(1,100);

创建初始点值对象。因为您不计算健身值,所以值为NaN在显示中。

vals = optimvalues(prob,x = xval,y = yval)
阀= 1x100 OptimizationValues vector with properties: Variables properties: x: [3.1472 4.0579 -3.7301 4.1338 1.3236 -4.0246 -2.2150 ... ] y: [-3.3782 2.9428 -1.8878 0.2853 -3.3435 1.0198 -2.3703 ... ] Objective properties: Objective: [NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... ]

Solve the problem usinggastarting from the initial point。放ga人口为100的选择。

opts = optimoptions(“ GA”,PopulationSize=100); [sol,fv] = solve(prob,vals,Solver=“ GA”,选项=选择)
使用GA解决问题。优化终止:健身价值的平均变化小于选项。功能耐力。
sol =带有字段的结构:X:1.0000 Y:1.0000
FV = 4.1061E-09

gareturns a solution very near the true solutionx = 1,y = 1和a fitness value near0

为创建初始点代理在具体问题具体分析的方法, create an优化价值object usingoptimvalues

创造optimization variables for a 2-D problem with Rosenbrock's function as the objective function.

x = optimvar("x",下部= -5,upperbound = 5);y = optimvar("y",下部= -5,upperbound = 5);rosenbrock =(10*(y -x。^2))。^2 +(1 -x)。^2;prob = optimproblem(Objective = RosenBrock);

创造constraints that the solution is in a disc of radius 2 about the origin and lies below the line y = 1 + x.

disc = x^2 + y^2 <= 2^2; prob.Constraints.disc = disc; line = y <= 1 + x; prob.Constraints.line = line;

创造40 random 2-D points within the bounds. The points must be row vectors.

RNGdefault%可再现性N = 40; xval = -5 + 10*rand(1,N); yval = -5 + 10*rand(1,N);

Evaluate Rosenbrock's function on the random points. The function values must be a row vector. This step is optional. If you do not provide the function values,代理评估该点的目标函数(xval,yval)。当您具有函数值时,您可以通过提供值作为数据来节省求解器的时间。

fval = zeros(1,N);fori = 1:N p0 = struct('X',xval(i),'y',Yval(i));fval(i)= evaluate(Rosenbrock,p0);end

评估这些点的约束。约束值必须是行向量。此步骤是可选的。如果您不提供约束值,代理评估点的约束函数(xval,yval)

discval = zeros(1,N); lineval = zeros(1,N);fori = 1:N p0 = struct('X',xval(i),'y',Yval(i));discval(i)=不可行(DISC,P0);lineVal(i)=不可行(线,p0);end

创建初始点值对象。

vals = optimvalues(prob,x = xval,y = yval,objective = fval,disc = discval,line = lineVal)
vals = 1x40具有属性的优化价值矢量:变量属性:x:[3.1472 4.0579 -3.7301 4.1338 1.3236 -4.0246 -2.2150 ...Objective: [1.1067e+04 3.1166e+04 1.2698e+04 1.9992e+04 2.3846e+03 ... ] Constraints properties: disc: [6.2803 13.8695 16.9638 21.8023 7.5568 12.2078 1.2024 0 ... ] line: [0 05.3853 0 0 2.9222 0.6709 0 0 0 0 0.1841 0 0 0 0 0 0 2.5648 ...]

Solve the problem using代理starting from the initial point

[sol,fv] = solve(prob,vals,Solver="surrogateopt")
使用代理解决问题。

图优化图函数包含轴对象。具有标题最佳功能值的轴对象:0.0415877包含一个类型行的对象。该对象代表最佳功能值。

替代之所以停止,是因为它超过了“选项”设置的函数评估限制限制。
sol =带有字段的结构:X:0.7961 y:0.6340
FV = 0.0416

代理returns a solution somewhat near the true solutionx = 1,y = 1具有目标函数值接近0

输入参数

全部收缩

优化问题,指定为优化问题目的。创造概率usingoptimproblem

To obtain useful output fromoptimvalues, you must also include some data in name-value arguments.

Name-Value Arguments

将可选的参数对Name1=Value1,...,NameN=ValueN, 在哪里Nameis the argument name and价值是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。

例子:瓦尔= optimvalues(x=xvals,y=yvals)

变量,命名为目标或命名约束的数据指定为真实的双阵列。指定变量的所有数据名称。目标和约束函数名称是可选的。

When you specifynval点,每个值的值dataNameargument must have the following dimensions.

概率。property.name 尺寸(值)
Scalar or vector numel(prob.property.name)-经过-nval
矩阵或数组 size(prob.property.name)-经过-nval

特别是dataName是向量,是dataName参数是一个矩阵nvalcolumns. For example, if the'X'variable is a row vector of length 2, andnvalis 3, then the'X'可变规范可能是:

瓦尔= optimvalues(概率,'X',[1 2 3;4 5 -6]);

该规范意味着'X'takes the three values[1,4],[2,5], 和[3,-6]

例子:对于标量'X'和两元素行矢量'y'NVAL = 2:val = optimValues(prob,x = [5,3],y = [1 2; 3 4])。输出瓦尔has two values:x = 5,y = [1 3]x = 3,y = [2 4]

数据类型:双倍的

未命名的目标函数的值,指定为真实的双阵列。值的大小与dataName

您可以通过两种方式指定多个目标函数的值以优化问题:

  • The客观的property of the optimization problem is a function handle, where the function returns a vector or array. In this case, specify the value as a matrix. Each matrix row represents the values of one objective at the various points. Each column represents the values of the various objectives at one point.

  • The客观的优化问题的属性具有多个命名目标。在这种情况下,使用其名称作为一个dataName争论。

这些求解器使用任何提供的目标函数值:

  • ga

  • gamultiobj

  • paretosearch

  • 代理

例子:For one objective and two points,瓦尔= optimvalues(概率,x=[3,5],Objective=[exp(3)+1,exp(5)-1])

数据类型:双倍的

价值s for an unnamed constraint function, specified as a real double array. The size of the values is the same as indataName

You can specify values of multiple constraint functions for optimization problems in two ways:

  • The约束property of the optimization problem is a function handle, where the function returns an array. In this case, specify the values as an array with one more dimension than the function returns.

  • The'Constraints'优化问题的属性具有多个命名约束。在这种情况下,使用其名称作为一个dataName争论。

These solvers use any supplied nonlinear constraint function values:

  • paretosearch

  • 代理

These solvers ensure that linear constraints are satisfied at all iterations or for all population members:

  • ga

  • gamultiobj

  • paretosearch

  • 模式搜索

  • 代理

例子:对于两个点和三个约束,val = optimValues(prob,x = [3,5],客观= [exp(3)+1,exp(5)-1],约束= [4 5; -7 -2; 0.2 12])

数据类型:双倍的

Output Arguments

全部收缩

点和函数值,返回为优化价值objects. The vector hasnvalentries, wherenval是积分数瓦尔

Version History

在R2022a中引入