Compareparetosearch
和gamultiobj.
此示例显示如何使用两者在Pareto正面创建一组点paretosearch
和gamultiobj.
。目标函数有两个目标和二维控制变量x
。目标职能mymulti3
在您的Matlab®会话中可用,当您单击按钮编辑或尝试此示例时。或者,复制mymulti3
code to your session. For speed of calculation, the function is vectorized.
typemymulti3
function f = mymulti3(x) % f(:,1) = x(:,1).^4 + x(:,2).^4 + x(:,1).*x(:,2) - (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;
Basic Example and Plots
Find Pareto sets for the objective functions usingparetosearch
和gamultiobj.
。Set theUseVectorized
option to真的
增加速度。包括可视化Pareto集的绘图功能。
rng.defaultnvars = 2;opts = Optimoptions(@gamultiobj,'UseVectorized',true,'plotfcn','gaplotpareto');[xga,fvalga,~,gaoutput] = gamultiobj(@(x)mymulti3(x),nvars,[],[],[],[],[],[],[],opts);
Optimization terminated: average change in the spread of Pareto solutions less than options.FunctionTolerance.
optsp = optimoptions('paretosearch','UseVectorized',true,'plotfcn',{'psplotparetof''psplotparetox'});[xp,fvalp,〜,psOutput] = paretosearch(@(x)mymulti3(x),nvars,[],[],[],[],[],[],[],OPTSP);
发现帕累托集,满足了约束。优化完成,因为帕累托集的卷的相对变化小于'选项.PartetosetchangeTolerance',并满足于“选项”中的约束。
通过使用计算Pareto前面的理论上精确点mymulti4
。这mymulti4
在MATLAB会话中可用功能在您单击按钮以编辑或尝试此示例。
typemymulti4
功能城市= 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
function evaluates the gradients of the two objective functions. Next, for a range of values ofx(2)
, useFzero.
找到渐变正好并行的点,这是输出的位置mout
= 0.
a = [fzero(@(t)mymulti4([t,-3.15]),[2,3]), - 3.15];forJJ = Linspace(-3.125,-1.89,50)a = [a; [fzero(@(t)mymulti4([t,jj]),[2,3]),JJ]];endfigure plot(fvalp(:,1),fvalp(:,2),'博');抓住在fs = mymulti3(a);情节(Fvalga(:,1),Fvalga(:,2),'r *');绘图(FS(:,1),FS(:,2),'k。') legend('paretosearch','Gamultiobj','True')Xlabel('Objective 1')ylabel('Objective 2') 抓住离开
gamultiobj.
在客观函数空间中找到略微更宽的点。绘制判定变量中的解金宝搏官方网站决方案,以及理论最优帕累托曲线和两个目标函数的轮廓图。
(x, y) = meshgrid(1.9: .01:3.1, -3.2:幅:-1.8);mydata = mymulti3([x(:),y(:)]); myff = sqrt(mydata(:,1) + 39);% Spaces the contours bettermygg = sqrt(mydata(:,2) + 28);% Spaces the contours bettermyff = reshape(myff,size(x)); mygg = reshape(mygg,size(x)); figure; hold在轮廓(x,y,mygg,50)轮廓(x,y,myff,50)绘图(xp(:,1),xp(:,2),'博') plot(xga(:,1),xga(:,2),'r *') plot(a(:,1),a(:,2),'-k')Xlabel('x(1)')ylabel('x(2)') 抓住离开
不像paretosearch
solution, thegamultiobj.
solution has points at the extreme ends of the range in objective function space. However, theparetosearch
解决方案具有更多的点,该点更接近客观函数空间和决策变量空间中的真实解决方案。在使用默认选项时,每个求解器的Pareto前面的点数不同。
Shifted Problem
What happens if the solution to your problem has control variables that are large? Examine this case by shifting the problem variables. For an unconstrained problem,gamultiobj.
可能会失败,而且paretosearch
is more robust to such shifts.
更容易比较,为每个求解器指定帕累托前面的35分。
Shift = [20,-30];fun = @(x)mymulti3(x + shift);选择.Populationsize = 100;% opts.ParetoFraction = 35[xgash,fvalgash,~,gashoutput] = gamultiobj(fun,nvars,[],[],[],[],[],[],opts);
Optimization terminated: average change in the spread of Pareto solutions less than options.FunctionTolerance.
gamultiobj.
fails to find a useful Pareto set.
optsp.plotfcn = [];optsp.paretosetsize = 35;[xpsh,fvalpsh,〜,pshoutput] = paretosearch(fun,nvars,[],[],[],[],[],[],[],OPTSP);
发现帕累托集,满足了约束。优化完成,因为帕累托集的卷的相对变化小于'选项.PartetosetchangeTolerance',并满足于“选项”中的约束。
figure plot(fvalpsh(:,1),fvalpsh(:,2),'博');抓住在绘图(FS(:,1),FS(:,2),'k。') legend('paretosearch','True')Xlabel('Objective 1')ylabel('Objective 2') 抓住离开
paretosearch
finds solution points spread evenly over nearly the entire possible range.
添加界限,甚至相当松散,有助于两者gamultiobj.
和paretosearch
to find appropriate solutions. Set lower bounds of-50
in each component, and upper bounds of50
。
opts.plotfcn = [];optsp.plotfcn = [];lb = [-50,-50];UB = -LB;[xgash,fvalgash,〜,gashoutput] = gamultiobj(有趣,nvars,[],[],[],[],LB,UB,OPTS);
Optimization terminated: average change in the spread of Pareto solutions less than options.FunctionTolerance.
[xpsh2,fvalpsh2,〜,pshoutput2] = paretosearch(fun,nvars,[],[],[],[],LB,UB,[],OPTSP);
发现帕累托集,满足了约束。优化完成,因为帕累托集的卷的相对变化小于'选项.PartetosetchangeTolerance',并满足于“选项”中的约束。
figure plot(fvalpsh2(:,1),fvalpsh2(:,2),'博');抓住在绘图(FVALGASH(:,1),FVALGASH(:,2),'r *');绘图(FS(:,1),FS(:,2),'k。') legend('paretosearch','Gamultiobj','True')Xlabel('Objective 1')ylabel('Objective 2') 抓住离开
In this case, both solvers find good solutions.
Startparetosearch
从gamultiobj.
解决方案
Obtain a similar range of solutions from the solvers by startingparetosearch
来自gamultiobj.
解决方案。
optsp.initialpoints = xgash;[xpsh3,fvalpsh3,〜,pshoutput3] = paretosearch(fun,nvars,[],[],[],[],LB,UB,[],OPTSP);
发现帕累托集,满足了约束。优化完成,因为帕累托集的卷的相对变化小于'选项.PartetosetchangeTolerance',并满足于“选项”中的约束。
figure plot(fvalpsh3(:,1),fvalpsh3(:,2),'博');抓住在绘图(FVALGASH(:,1),FVALGASH(:,2),'r *');绘图(FS(:,1),FS(:,2),'k。') legend('paretosearch','Gamultiobj','True')Xlabel('Objective 1')ylabel('Objective 2') 抓住离开
Now theparetosearch
solution is similar to thegamultiobj.
solution, although some of the solution points differ.
从单目标解决方案开始金宝搏官方网站
Another way of obtaining a good solution is to start from the points that minimize each objective function separately.
From the multiobjective function, create a single-objective function that chooses each objective in turn. Use the shifted function from the previous section. Because you are giving good start points to the solvers, you do not need to specify bounds.
nobj = 2;%目标数量x0 = -shift;% Initial point for single-objective minimizationuncmin = cell(nobj,1);% Cell array to hold the single-objective minimaAllfuns = Zeros(Nobj,2);% Hold the objective function valuesEFLAG = Zeros(Nobj,1);fopts = Optimoptions('patternsearch','展示','离开');% Use an appropriate solver herefori = 1:nobj indi = zeros(nobj,1);% Choose the objective to minimizeIndi(i)= 1;Funi = @(x)点(乐趣(x),Indi);[undmin {i},〜,eflag(i)] = patternsearch(funi,x0,[],[],[],[],[],[],[],FOPT);% Minimize objective iallfuns(i,:) = fun(uncmin{i});enduncmin = cell2mat(uncmin);%起点矩阵
Startparetosearch
从单个客观的最低点,请注意,它在其解决方案中具有全方位。金宝搏官方网站paretosearch
将随机初始点添加到所提供的点,以便至少有人口options.ParetoSetSize
individuals. Similarly,gamultiobj.
将随机点添加到所提供的点以获得至少的人口(options.PopulationSize)*(options.ParetoFraction)
individuals.
Optsp = Optimoptions(Optsp,'InitialPoints',肆意);[Xpinit,Fvalpinit,〜,Outputpinit] = Paretosearch(Fun,NVARS,[],[],[],[],[],[],[],OPTSP);
发现帕累托集,满足了约束。优化完成,因为帕累托集的卷的相对变化小于'选项.PartetosetchangeTolerance',并满足于“选项”中的约束。
Now solve the problem usinggamultiobj.
starting from the initial points.
opts = optimoptions(opts,'InitialPopulationMatrix',肆意);[xgash2,fvalgash2,~,gashoutput2] = gamultiobj(fun,nvars,[],[],[],[],[],[],opts);
Optimization terminated: average change in the spread of Pareto solutions less than options.FunctionTolerance.
图绘图(fvalpinit(:,1),fvalpinit(:,2),'博');抓住在plot(fvalgash2(:,1),fvalgash2(:,2),'r *');绘图(FS(:,1),FS(:,2),'k。')绘图(Allfuns(:,1),Allfuns(:,2),'gs','MarkerSize',12) legend('paretosearch','Gamultiobj','True','开始点')Xlabel('Objective 1')ylabel('Objective 2') 抓住离开
两个求解器都填充了极端点之间的帕累托前部,具有合理准确和间隔良好的解决方案。金宝搏官方网站
View the final points in decision variable space.
figure; hold在xx = X - Shift(1);yy = y - shift(2);轮廓(xx,yy,mygg,50)轮廓(xx,yy,myff,50)绘图(xpinit(:,1),xpinit(:,2),'博') plot(xgash2(:,1),xgash2(:,2),'r *') ashift = a - shift; plot(ashift(:,1),ashift(:,2),'-k')情节(贸易委员会(:,1),unclmin(:,2),'gs','MarkerSize',12);Xlabel('x(1)')ylabel('x(2)') 抓住离开