相比Paretosearch
andgamultiobj
This example shows how to create a set of points on the Pareto front using bothParetosearch
andgamultiobj
。这objective function has two objectives and a two-dimensional control variableX
。这objective functionmymulti3
is 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;
基本示例和图
使用使用Paretosearch
andgamultiobj
。设置使用vectorized
option 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;
优化终止:帕累托解决方案的平均变化小于选项。功能耐受性。金宝搏官方网站
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'.
帕累托f计算理论上精确点ront by usingmymulti4
。这mymulti4
function 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)
,,,,usefzero
to 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
gamultiobj
finds 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
Unlike theParetosearch
solution, thegamultiobj
solution has points at the extreme ends of the range in objective function space. However, theParetosearch
solution 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.
转移的问题
如果解决问题的解决方案具有大型控制变量,会发生什么?通过移动问题变量来检查此情况。对于不受约束的问题,gamultiobj
can 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);
优化终止:帕累托解决方案的平均变化小于选项。功能耐受性。金宝搏官方网站
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
Paretosearch
找到求解点在几乎整个可能的范围内均匀分布。
Adding bounds, even fairly loose ones, helps bothgamultiobj
andParetosearch
找到适当的解决方案。金宝搏官方网站设置下限-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
在这种情况下,两个求解器都可以找到好的解决方案。金宝搏官方网站
开始Paretosearch
fromgamultiobj
Solution
通过启动从求解器获得类似的解决方案金宝搏官方网站Paretosearch
from thegamultiobj
solution.
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
现在Paretosearch
解决方案类似于gamultiobj
solution, 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
开始Paretosearch
from the single-objective minimum points and note that it has a full range in its solutions.Paretosearch
adds random initial points to the supplied ones in order to have a population of at leastoptions.paretosetsize
个人。相似地,gamultiobj
adds 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
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