paretosearch
在帕累托集中查找点
语法
说明
示例
在二维变量的双目标函数的帕累托前沿上找到点。
fun = @(x)[norm(x-[1,2])^2;norm(x+[2,1])^2]; rng default % For reproducibility x = paretosearch(fun,2);
Pareto set found that satisfies the constraints. Optimization completed because the relative change in the volume of the Pareto set is less than 'options.ParetoSetChangeTolerance' and constraints are satisfied to within 'options.ConstraintTolerance'.
将解绘制为散点图。
plot(x(:,1),x(:,2),'m*') xlabel('x(1)') ylabel('x(2)')
理论上,这个问题的解是从 [-2,-1]
到 [1,2]
的一条直线。paretosearch
返回靠近这条线的等距点。
为受线性约束 x(1) + x(2) <= 1
约束的二维双目标问题创建帕累托前沿。
fun = @(x)[norm(x-[1,2])^2;norm(x+[2,1])^2]; A = [1,1]; b = 1; rng default % For reproducibility x = paretosearch(fun,2,A,b);
Pareto set found that satisfies the constraints. Optimization completed because the relative change in the volume of the Pareto set is less than 'options.ParetoSetChangeTolerance' and constraints are satisfied to within 'options.ConstraintTolerance'.
将解绘制为散点图。
plot(x(:,1),x(:,2),'m*') xlabel('x(1)') ylabel('x(2)')
理论上,这个问题的解是从 [-2,-1]
到 [0,1]
的一条直线。paretosearch
返回靠近这条线的等距点。
为二维双目标问题创建帕累托前沿,受限于边界 x(1) >= 0
和 x(2) <= 1
。
fun = @(x)[norm(x-[1,2])^2;norm(x+[2,1])^2]; lb = [0,-Inf]; % x(1) >= 0 ub = [Inf,1]; % x(2) <= 1 rng default % For reproducibility x = paretosearch(fun,2,[],[],[],[],lb,ub);
Pareto set found that satisfies the constraints. Optimization completed because the relative change in the volume of the Pareto set is less than 'options.ParetoSetChangeTolerance' and constraints are satisfied to within 'options.ConstraintTolerance'.
将解绘制为散点图。
plot(x(:,1),x(:,2),'m*') xlabel('x(1)') ylabel('x(2)')
所有解都在约束边界 x(1) = 0
或 x(2) = 1
上。
为二维双目标问题创建帕累托前沿,受边界 -1.1 <= x(i) <= 1.1
和非线性约束 norm(x)^2 <= 1.2
约束。非线性约束函数出现在此示例的末尾,如果您将此示例作为实时脚本运行,则该函数有效。要以其他方式运行此示例,请将非线性约束函数作为文件包含在您的 MATLAB® 路径中。
为了更好地看到非线性约束的效果,请设置选项以使用较大的帕累托集大小。
rng default % For reproducibility fun = @(x)[norm(x-[1,2])^2;norm(x+[2,1])^2]; lb = [-1.1,-1.1]; ub = [1.1,1.1]; options = optimoptions('paretosearch','ParetoSetSize',200); x = paretosearch(fun,2,[],[],[],[],lb,ub,@circlecons,options);
Pareto set found that satisfies the constraints. Optimization completed because the relative change in the volume of the Pareto set is less than 'options.ParetoSetChangeTolerance' and constraints are satisfied to within 'options.ConstraintTolerance'.
将解绘制为散点图。包括圆形约束边界的图。
figure plot(x(:,1),x(:,2),'k*') xlabel('x(1)') ylabel('x(2)') hold on rectangle('Position',[-1.2 -1.2 2.4 2.4],'Curvature',1,'EdgeColor','r') xlim([-1.2,0.5]) ylim([-0.5,1.2]) axis square hold off
具有正 x(1)
值或负 x(2)
值的解点接近非线性约束边界。
function [c,ceq] = circlecons(x) ceq = []; c = norm(x)^2 - 1.2; end
为了监控 paretosearch
的进度,请指定 'psplotparetof'
绘图函数。
fun = @(x)[norm(x-[1,2])^2;norm(x+[2,1])^2]; options = optimoptions('paretosearch','PlotFcn','psplotparetof'); lb = [-4,-4]; ub = -lb; x = paretosearch(fun,2,[],[],[],[],lb,ub,[],options);
Pareto set found that satisfies the constraints. Optimization completed because the relative change in the volume of the Pareto set is less than 'options.ParetoSetChangeTolerance' and constraints are satisfied to within 'options.ConstraintTolerance'.
该解看起来像一个半径为 18 的四分之一圆弧,可以证明其为解析解。
通过使用 paretosearch
和 x
输出调用 fval
,在函数空间和参数空间中获得帕累托前沿。设置选项以在函数空间和参数空间中绘制帕累托集。
fun = @(x)[norm(x-[1,2])^2;norm(x+[2,1])^2]; lb = [-4,-4]; ub = -lb; options = optimoptions('paretosearch','PlotFcn',{'psplotparetof' 'psplotparetox'}); rng default % For reproducibility [x,fval] = paretosearch(fun,2,[],[],[],[],lb,ub,[],options);
Pareto set found that satisfies the constraints. Optimization completed because the relative change in the volume of the Pareto set is less than 'options.ParetoSetChangeTolerance' and constraints are satisfied to within 'options.ConstraintTolerance'.
目标函数空间中的解析解是半径为 18 的四分之一圆弧。在参数空间中,解析解是一条从 [-2,-1]
到 [1,2]
的直线。解点接近解析曲线。
设置选项来监控帕累托集解过程。另外,从 paretosearch
获取更多输出,以便您了解解过程。
options = optimoptions('paretosearch','Display','iter',... 'PlotFcn',{'psplotparetof' 'psplotparetox'}); fun = @(x)[norm(x-[1,2])^2;norm(x+[2,1])^2]; lb = [-4,-4]; ub = -lb; rng default % For reproducibility [x,fval,exitflag,output] = paretosearch(fun,2,[],[],[],[],lb,ub,[],options);
Iter F-count NumSolutions Spread Volume 0 60 11 - 3.7872e+02 1 386 12 7.6126e-01 3.4654e+02 2 702 27 9.5232e-01 2.9452e+02 3 1029 27 6.6332e-02 2.9904e+02 4 1357 36 1.3874e-01 3.0070e+02 5 1690 37 1.5379e-01 3.0200e+02 6 2014 50 1.7828e-01 3.0252e+02 7 2214 59 1.8536e-01 3.0320e+02 8 2344 60 1.9435e-01 3.0361e+02 9 2464 60 2.1055e-01 3.0388e+02 Pareto set found that satisfies the constraints. Optimization completed because the relative change in the volume of the Pareto set is less than 'options.ParetoSetChangeTolerance' and constraints are satisfied to within 'options.ConstraintTolerance'.
检查附加输出。
fprintf('Exit flag %d.\n',exitflag)
Exit flag 1.
disp(output)
iterations: 10 funccount: 2464 volume: 303.6076 averagedistance: 0.0250 spread: 0.2105 maxconstraint: 0 message: 'Pareto set found that satisfies the constraints. ↵↵Optimization completed because the relative change in the volume of the Pareto set ↵is less than 'options.ParetoSetChangeTolerance' and constraints are satisfied to within ↵'options.ConstraintTolerance'.' rngstate: [1×1 struct]
获取并检查帕累托前沿约束残差。创建一个具有线性不等式约束 sum(x) <= -1/2
和非线性不等式约束 norm(x)^2 <= 1.2
的问题。为了提高准确性,在帕累托前沿使用 200 个点,以及 ParetoSetChangeTolerance
的 1e-7
,并给出自然边界 -1.2 <= x(i) <= 1.2
。
非线性约束函数出现在此示例的末尾,如果您将此示例作为实时脚本运行,则该函数有效。要以其他方式运行此示例,请将非线性约束函数作为文件包含在您的 MATLAB® 路径中。
fun = @(x)[norm(x-[1,2])^2;norm(x+[2,1])^2]; A = [1,1]; b = -1/2; lb = [-1.2,-1.2]; ub = -lb; nonlcon = @circlecons; rng default % For reproducibility options = optimoptions('paretosearch','ParetoSetChangeTolerance',1e-7,... 'PlotFcn',{'psplotparetof' 'psplotparetox'},'ParetoSetSize',200);
使用所有输出调用 paretosearch
。
[x,fval,exitflag,output,residuals] = paretosearch(fun,2,A,b,[],[],lb,ub,nonlcon,options);
Pareto set found that satisfies the constraints. Optimization completed because the relative change in the volume of the Pareto set is less than 'options.ParetoSetChangeTolerance' and constraints are satisfied to within 'options.ConstraintTolerance'.
与无约束的集合相比,不等式约束减少了帕累托集的大小。检查返回的残差。
fprintf('The maximum linear inequality constraint residual is %f.\n',max(residuals.ineqlin))
The maximum linear inequality constraint residual is 0.000000.
fprintf('The maximum nonlinear inequality constraint residual is %f.\n',max(residuals.ineqnonlin))
The maximum nonlinear inequality constraint residual is -0.000537.
返回的最大残差为负,这意味着所有返回的点都是可行的。返回的最大残差接近于零,这意味着每个约束对于某些点都是有效的。
function [c,ceq] = circlecons(x) ceq = []; c = norm(x)^2 - 1.2; end
输入参数
变量的数目,指定为正整数。求解器传递长度从 nvars
到 fun
的行向量。
示例: 4
数据类型: double
线性不等式约束,指定为实矩阵。A
是 M
×nvars
矩阵,其中 M
是不等式的数目。
A
以如下形式编写 M
个线性不等式
A*x <= b
,
其中,x
是由 nvars
个变量组成的列向量 x(:)
,b
是具有 M
个元素的列向量。
例如,要指定
x1 +2x2 ≤10
3x1 +4x2 ≤20
5x1 +6x2 ≤30,
提供以下约束:
A = [1,2;3,4;5,6]; b = [10;20;30];
示例: 要指定控制项变量总和等于或小于 1,请给出约束 A = ones(1,N)
和 b = 1
。
数据类型: double
线性不等式约束,指定为实数向量。b
是与 A
矩阵相关的包含 M
个元素的向量。如果将 b
作为行向量传递,求解器会在内部将 b
转换为列向量 b(:)
。
b
以如下形式编写 M
个线性不等式
A*x <= b
,
其中,x
是由 N
个变量组成的列向量 x(:)
,A
是大小为 M
×N
的矩阵。
例如,要指定
x1 +2x2 ≤10
3x1 +4x2 ≤20
5x1 +6x2 ≤30,
提供以下约束:
A = [1,2;3,4;5,6]; b = [10;20;30];
示例: 要指定控制项变量总和等于或小于 1,请给出约束 A = ones(1,N)
和 b = 1
。
数据类型: double
线性等式约束,指定为实矩阵。Aeq
是 Me
×nvars
矩阵,其中 Me
是等式的数目。
Aeq
以如下形式编写 Me
个线性等式
Aeq*x = beq
,
其中,x
是由 N
个变量组成的列向量 x(:)
,beq
是具有 Me
个元素的列向量。
例如,要指定
x1 + 2x2 + 3x3 = 10
2x1 + 4x2 + x3 = 20,
提供以下约束:
Aeq = [1,2,3;2,4,1]; beq = [10;20];
示例: 要指定控制项变量总和为 1,请给出约束 Aeq = ones(1,N)
和 beq = 1
。
数据类型: double
线性等式约束,指定为实数向量。beq
是与 Aeq
矩阵相关的包含 Me
个元素的向量。如果将 beq
作为行向量传递,求解器会在内部将 beq
转换为列向量 beq(:)
。
beq
以如下形式编写 Me
个线性等式
Aeq*x = beq
,
其中,x
是由 N
个变量组成的列向量 x(:)
,Aeq
是大小为 Meq
×N
的矩阵。
例如,要指定
x1 + 2x2 + 3x3 = 10
2x1 + 4x2 + x3 = 20,
提供以下约束:
Aeq = [1,2,3;2,4,1]; beq = [10;20];
示例: 要指定控制项变量总和为 1,请给出约束 Aeq = ones(1,N)
和 beq = 1
。
数据类型: double
下界,指定为实数向量或双精度数组。lb
表示 lb
≤ x
≤ ub
中元素的下界。
paretosearch
在内部将数组 lb
转换为向量 lb(:)
。
示例: lb = [0;-Inf;4]
表示 x(1) ≥ 0
,x(3) ≥ 4
。
数据类型: double
上界,指定为实数向量或双精度数组。ub
表示 lb
≤ x
≤ ub
中元素的上界。
paretosearch
在内部将数组 ub
转换为向量 ub(:)
。
示例: ub = [Inf;4;10]
表示 x(2) ≤ 4
,x(3) ≤ 10
。
数据类型: double
非线性约束,指定为函数句柄或函数名称。nonlcon
函数接受行向量 x
并返回两个行向量 c(x)
和 ceq(x)
。
c(x)
是x
处的非线性不等式约束的行向量。对于c
的所有条目,paretosearch
函数尝试满足c(x) <= 0
。ceq(x)
必须返回[]
,因为目前paretosearch
不支持非线性等式约束。
如果将 UseVectorized
选项设置为 true
,则 nonlcon
将接受大小为 n
x nvars
的矩阵,其中该矩阵代表 n
个体。nonlcon
在第一个参量中返回大小为 n
x mc
的矩阵,其中 mc
是非线性不等式约束的数量。请参阅 向量化适应度函数。
例如,x = paretosearch(@myfun,nvars,A,b,Aeq,beq,lb,ub,@mycon)
,其中 mycon
是一个 MATLAB® 函数,如下所示:
function [c,ceq] = mycon(x) c = ... % Compute nonlinear inequalities at x. ceq = [] % No nonlinear equalities at x.
有关详细信息,请参阅非线性约束。
数据类型: char
| function_handle
| string
优化选项,指定为 optimoptions
的输出或结构体。
{}
表示默认值。请参阅 模式搜索选项 中的选项详细信息。
适用于 paretosearch
的选项
选项 | 描述 | 值 |
---|---|---|
| 约束的容差。 对于 options 结构体,使用 | 非负标量 | |
| 显示级别。 | 'off' | 'iter' | 'diagnose' | {'final'} |
|
| 具有 |
| 目标函数评估的最大次数。 对于 options 结构体,使用 | 非负整数 | |
| 最大迭代次数。 对于 options 结构体,使用 | 非负整数 | |
| 允许优化的总时间(以秒为单位)。 对于 options 结构体,使用 | 非负标量 | |
| 网格大小的容差。 对于 options 结构体,使用 | 非负标量 | |
| 要轮询的模式的最小部分。 | 从 0 到 1 的标量 | |
| 优化函数在每次迭代时调用的函数。指定为函数句柄或函数句柄元胞数组。 对于 options 结构体,使用 | 函数句柄或函数句柄元胞数组 | |
| 当迭代窗口内的停止测量的相对变化小于或等于
请参阅 paretosearch 算法的定义。 当任何适用测量的相对变化小于 注意 不建议设置 | 非负标量 | |
| 帕累托集中的点数。 | 正整数 | |
| 模式搜索的输出图。指定为内置绘图函数的名称、函数句柄,或者内置绘图函数或函数句柄名称的元胞数组。 对于 options 结构体,使用 |
具有多个目标: 只有一个目标: |
| 模式搜索中采用的轮询策略。 注意 当问题具有线性等式约束时,您不能使用 MADS 轮询。 |
|
| 并行计算目标和非线性约束函数。请参阅向量化和并行选项和如何在 Global Optimization Toolbox 中使用并行处理。 注意 必须将 从 R2019a 开始,当您将 |
|
| 指定函数是否向量化。请参阅向量化和并行选项和向量化目标和约束函数。 注意 必须将 对于 options 结构体,使用 |
|
示例: options = optimoptions('paretosearch','Display','none','UseParallel',true)
问题结构体,指定为含有以下字段的结构体:
objective
- 目标函数nvars
- 变量个数Aineq
- 线性不等式约束矩阵bineq
- 线性不等式约束Aeq
-线性等式约束矩阵beq
-线性等式约束lb
-x
的下界ub
-x
的上界nonlcon
- 非线性约束函数solver
—'paretosearch'
options
- 使用optimoptions
创建的选项rngstate
- 可选字段,用于重置随机数生成器的状态
注意
problem
中的所有字段都是必填项,但 rngstate
除外,它是可选的。
数据类型: struct
输出参量
帕累托点,以 m
×nvars
数组形式返回,其中 m
是帕累托前沿上的点数。x
的每行表示帕累托前沿上的一个点。
帕累托前沿上的函数值,以 m
×nf
数组的形式返回。m
是帕累托前沿上的点数,nf
是目标函数的数量。fval
的每行表示 x
中一个帕累托点的函数值。
原因 paretosearch
停止,以此表中的一个整数值返回。
退出标志 | 停止条件 |
---|---|
1 | 满足下列条件之一。
|
0 | 迭代次数超过 options.MaxIterations 或函数计算次数超过 options.MaxFunctionEvaluations 。 |
-1 | 优化由输出函数或绘图函数停止。 |
-2 | 求解器找不到满足所有约束的点。 |
-5 | 优化时间超过 options.MaxTime 。 |
有关优化过程的信息,以包含下列字段的结构体形式返回:
iterations
- 总迭代次数。funccount
-函数计算总数。volume
- 由函数空间中的帕累托点形成的集合的超体积。请参阅 paretosearch 算法的定义。averagedistance
-函数空间中帕累托点的平均距离测量。请参阅 paretosearch 算法的定义。spread
-帕累托点的平均扩展测量值。请参阅 paretosearch 算法的定义。maxconstraint
- 最大约束违反值(如果有)。message
- 算法终止的原因。rngstate
- 算法开始之前 MATLAB 随机数生成器的状态。当您使用随机轮询方法(例如rngstate
)或使用创建初始种群的默认准随机方法时,您可以使用'MADSPositiveBasis2N'
中的值来重现输出。请参阅 重现结果,其中讨论了ga
的相同技术。
详细信息
算法
paretosearch
使用模式搜索来搜索帕累托前沿上的点。有关详细信息,请参阅paretosearch 算法。
替代功能
App
优化实时编辑器任务为 paretosearch
提供了一个可视化界面。
扩展功能
要并行运行,请将 'UseParallel'
选项设置为 true
。
options = optimoptions('
solvername
','UseParallel',true)
有关详细信息,请参阅如何在 Global Optimization Toolbox 中使用并行处理。
版本历史记录
在 R2018b 中推出
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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)