Main Content

相比Paretosearchandgamultiobj

This example shows how to create a set of points on the Pareto front using bothParetosearchandgamultiobj。这objective function has two objectives and a two-dimensional control variableX。这objective functionmymulti3is available in your MATLAB® session when you click the button to edit or try this example. Alternatively, copy themymulti3代码到您的会话。为了计算速度,该函数被矢量化。

类型mymulti3
函数f = mymulti3(x)%f(:,1)= x(:,1)。^4 + x(:,2)。^4 + x(:,1)。(x(:,1)。^2)。*(x(:,2)。^2)-9*x(:,1)。^2;f(:,2)= x(:,2)。^4 + x(:,1)。^4 + x(:,1)。*x(:,2) - (x(:,1)。^2)。*(x(:,2)。^2) + 3*x(:,2)。^3;

基本示例和图

使用使用Paretosearchandgamultiobj。设置使用vectorizedoption totrue为了added speed. Include a plot function to visualize the Pareto set.

rng默认nvars = 2; opts = optimoptions(@gamultiobj,“使用矢量”,真的,'PlotFcn',,,,'gaplotpareto');[XGA,fvalga,〜,gaoutput] = gamultiobj(@(x)mymulti3(x),nvars,[],[],[],[],[],[],[],[],[],[],[],opts;
优化终止:帕累托解决方案的平均变化小于选项。功能耐受性。金宝搏官方网站

Figure Genetic Algorithm contains an axes object. The axes object with title Pareto front contains an object of type line.

optsp = optimoptions('Paretosearch',,,,“使用矢量”,真的,'PlotFcn',,,,{'Psplotparetof'“ psplotparetox”}); [xp,fvalp,~,psoutput] = paretosearch(@(x)mymulti3(x),nvars,[],[],[],[],[],[],[],optsp);
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'.

图ParetoSearch包含2个轴对象。轴对象1带有标题Pareto正面的对象包含类型线的对象。带有标题参数空间的轴对象2包含类型行的对象。

帕累托f计算理论上精确点ront by usingmymulti4。这mymulti4function is available in your MATLAB session when you click the button to edit or try this example.

类型mymulti4
功能城市= mymulti4 (x) % gg = [4 * x (1) ^ 3 + x (2) -2*x(1)*(x(2)^2) - 18*x(1); x(1)+4*x(2)^3-2*(x(1)^2)*x(2)]; gf = gg + [18*x(1);9*x(2)^2]; mout = gf(1)*gg(2) - gf(2)*gg(1);

mymulti4功能评估两个目标函数的梯度。接下来,对于一系列值x(2),,,,usefzeroto locate the point where the gradients are exactly parallel, which is where the outputmout= 0。

a = [fzero(@(t)mymulti4([t,-3.15]),[2,3]),-3.15];为了jj = linspace(-3.125,-1.89,50) a = [a;[fzero(@(t)mymulti4([t,jj]),[2,3]),jj]];结尾图图(fvalp(:,1),fvalp(:,2),,'bo');抓住onfs = mymulti3(a); plot(fvalga(:,1),fvalga(:,2),'r*');绘图(fs(:1),fs(:,2),'k.') 传奇('Paretosearch',,,,'Gamultiobj',,,,'真的') xlabel(“目标1”) ylabel(“目标2”) holdoff

图包含一个轴对象。这axes object contains 3 objects of type line. These objects represent Paretosearch, Gamultiobj, True.

gamultiobjfinds points with a slightly wider spread in objective function space. Plot the solutions in decision variable space, along with the theoretical optimal Pareto curve and a contour plot of the two objective functions.

[x,y] = meshgrid(1.9:.01:3.1,-3.2:.01:-1.8);mydata = mymulti3([x(:),y(:)]);myff = sqrt(mydata(::,1) + 39);%空间轮廓更好mygg = sqrt(mydata(::,2) + 28);%空间轮廓更好myff = reshape(myff,size(x));mygg = reshape(mygg,size(x));数字;抓住oncontour(x,y,mygg,50) contour(x,y,myff,50) plot(xp(:,1),xp(:,2),'bo')图(xga(:,1),xga(:,2),,'r*')图(a(:,1),a(:,2),'-k') xlabel('x(1)') ylabel('x(2)') holdoff

图包含一个轴对象。轴对象包含5个类型轮廓,行的对象。

Unlike theParetosearchsolution, thegamultiobjsolution has points at the extreme ends of the range in objective function space. However, theParetosearchsolution has more points that are closer to the true solution in both objective function space and decision variable space. The number of points on the Pareto front is different for each solver when you use the default options.

转移的问题

如果解决问题的解决方案具有大型控制变量,会发生什么?通过移动问题变量来检查此情况。对于不受约束的问题,gamultiobjcan fail, whileParetosearch这种转变更强大。

For easier comparison, specify 35 points on the Pareto front for each solver.

shift = [20,-30]; fun = @(x)mymulti3(x+shift); opts.PopulationSize = 100;%选择。[Xgash,fvalgash,〜,gashoutput] = gamultiobj(fun,nvars,[],[],[],[],[],[],[],[],[],opts);
优化终止:帕累托解决方案的平均变化小于选项。功能耐受性。金宝搏官方网站

Figure Genetic Algorithm contains an axes object. The axes object with title Pareto front contains an object of type line.

gamultiobj未能找到有用的帕累托集。

optsp.PlotFcn = []; optsp.ParetoSetSize = 35; [xpsh,fvalpsh,~,pshoutput] = paretosearch(fun,nvars,[],[],[],[],[],[],[],optsp);
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'.
图图(fvalpsh(:,1),fvalpsh(::,2),,'bo');抓住on绘图(fs(:1),fs(:,2),'k.') 传奇('Paretosearch',,,,'真的') xlabel(“目标1”) ylabel(“目标2”) holdoff

图包含一个轴对象。轴对象包含2个类型行的对象。这些对象代表paretosearch,true。

Paretosearch找到求解点在几乎整个可能的范围内均匀分布。

Adding bounds, even fairly loose ones, helps bothgamultiobjandParetosearch找到适当的解决方案。金宝搏官方网站设置下限-50在每个组件中,50

opts.PlotFcn = []; optsp.PlotFcn = []; lb = [-50,-50]; ub = -lb; [xgash,fvalgash,~,gashoutput] = gamultiobj(fun,nvars,[],[],[],[],lb,ub,opts);
优化终止:帕累托解决方案的平均变化小于选项。功能耐受性。金宝搏官方网站
[xpsh2,fvalpsh2,~,pshoutput2] = paretosearch(fun,nvars,[],[],[],[],lb,ub,[],optsp);
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'.
图图(fvalpsh2(:,1),fvalpsh2(:,2),'bo');抓住onplot(fvalgash(:,1),fvalgash(:,2),'r*');绘图(fs(:1),fs(:,2),'k.') 传奇('Paretosearch',,,,'Gamultiobj',,,,'真的') xlabel(“目标1”) ylabel(“目标2”) holdoff

图包含一个轴对象。这axes object contains 3 objects of type line. These objects represent Paretosearch, Gamultiobj, True.

在这种情况下,两个求解器都可以找到好的解决方案。金宝搏官方网站

开始ParetosearchfromgamultiobjSolution

通过启动从求解器获得类似的解决方案金宝搏官方网站Paretosearchfrom thegamultiobjsolution.

optsp.InitialPoints = xgash; [xpsh3,fvalpsh3,~,pshoutput3] = paretosearch(fun,nvars,[],[],[],[],lb,ub,[],optsp);
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(fvalpsh3(:,1),fvalpsh3(:,2),'bo');抓住onplot(fvalgash(:,1),fvalgash(:,2),'r*');绘图(fs(:1),fs(:,2),'k.') 传奇('Paretosearch',,,,'Gamultiobj',,,,'真的') xlabel(“目标1”) ylabel(“目标2”) holdoff

图包含一个轴对象。这axes object contains 3 objects of type line. These objects represent Paretosearch, Gamultiobj, True.

现在Paretosearch解决方案类似于gamultiobjsolution, although some of the solution points differ.

开始from Single-Objective Solutions

获得良好解决方案的另一种方法是从分别最小化每个目标函数的点开始。

从多目标函数中,创建一个单目标函数,依次选择每个目标。使用上一节的移位函数。因为您为求解器提供了良好的起点,所以您无需指定界限。

nobj = 2;% Number of objectivesx0 = -shift;单目标最小化的初始点%uncmin = cell(nobj,1);%单元阵列保持单目标最小值allfuns = zeros(nobj,2);%保持目标函数值eflag = zeros(nobj,1); fopts = optimoptions(“模式搜索”,,,,'Display',,,,'off');%在这里使用合适的求解器为了i = 1:nobj indi = zeros(nobj,1);%选择最小化目标indi(i) = 1; funi = @(x)dot(fun(x),indi); [uncmin{i},~,eflag(i)] = patternsearch(funi,x0,[],[],[],[],[],[],[],fopts);%最小化目标iallfuns(i,:) = fun(uncmin{i});结尾uncmin = cell2mat(uncmin);% Matrix of start points

开始Paretosearchfrom the single-objective minimum points and note that it has a full range in its solutions.Paretosearchadds random initial points to the supplied ones in order to have a population of at leastoptions.paretosetsize个人。相似地,gamultiobjadds random points to the supplied ones to obtain a population of at least(options.populationsize)*(options.paretofraction)个人。

optsp = optimoptions(optsp,“初始点”,uncmin);[xpinit,fvalpinit,~,outputpinit] = paretosearch(fun,nvars,[],[],[],[],[],[],[],optsp);
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'.

现在使用gamultiobj从初始点开始。

opts = optimoptions(opts,“初始人群”,uncmin);[xgash2,fvalgash2,〜,gashoutput2] = gamultiobj(fun,nvars,[],[],[],[],[],[],[],[],[],opts);
优化终止:帕累托解决方案的平均变化小于选项。功能耐受性。金宝搏官方网站
figure plot(fvalpinit(:,1),fvalpinit(:,2),'bo');抓住on绘图(fvalgash2(:,1),fvalgash2(:,2),,'r*');绘图(fs(:1),fs(:,2),'k.') plot(allfuns(:,1),allfuns(:,2),'gs',,,,'MarkerSize',12)传奇('Paretosearch',,,,'Gamultiobj',,,,'真的',,,,'Start Points') xlabel(“目标1”) ylabel(“目标2”) holdoff

图包含一个轴对象。这axes object contains 4 objects of type line. These objects represent Paretosearch, Gamultiobj, True, Start Points.

Both solvers fill in the Pareto front between the extreme points, with reasonably accurate and well-spaced solutions.

View the final points in decision variable space.

数字;抓住onXX= x - shift(1); yy = y - shift(2); contour(xx,yy,mygg,50) contour(xx,yy,myff,50) plot(xpinit(:,1),xpinit(:,2),'bo')图(xgash2(:,1),xgash2(:,2),,'r*')shift = a -shift;情节(Ashift(:,1),Ashift(:,2),'-k') plot(uncmin(:,1),uncmin(:,2),'gs',,,,'MarkerSize',,,,12); xlabel('x(1)') ylabel('x(2)') holdoff

图包含一个轴对象。轴对象包含6个类型轮廓,行的对象。

也可以看看

|

Related Topics