1 理论基础
1.1 多目标优化及Pareto最优解
图1 多目标优化问题
1.2 函数gamultiobj
1.3 函数gamultiobj中的一些基本概念
2 素例背景
2.1 问题描述
2.2 解题思路及步骤
(2)在命令行调用GUI:
optimtool('gamultiobj')
gamultiobj是使用遗传算法解决多目标优化问题的函数。它试图解决以下形式的多目标问题:
min F(X) subject to: AX <= b, AeqX = beq (线性约束)
X lb <= X <= ub (边界约束)
X = gamultiobj(FITNESSFCN,NVARS)找到在FITNESSFCN中定义的目标函数的局部帕累托集X。NVARS是优化问题的维数(决策变量的数量)。FITNESSFCN接受大小为1-by-NVARS的向量X,并返回在决策变量处评估的大小为1-by-numberOfObjectives的向量。X是具有NVARS列的矩阵。X中的行数与帕累托解的数量相同。帕累托集中的所有解同样优,取决于应用程序的设计者选择帕累托集中的解。
X = gamultiobj(FITNESSFCN,NVARS,A,b)找到在FITNESSFCN中定义的目标函数的局部帕累托集X,受制于线性不等式A*X <= B。仅支持默认的PopulationType选项('doubleVector')的线性约束;不支持其他种群类型,例如'bitString'和'custom'。
X = gamultiobj(FITNESSFCN,NVARS,A,b,Aeq,beq)找到在FITNESSFCN中定义的目标函数的局部帕累托集X,受制于线性等式AeqX = beq以及线性不等式AX <= b。(如果不存在不等式,则设置A=[]和b=[]。)仅支持默认的PopulationType选项('doubleVector')的线性约束;不支持其他种群类型,例如'bitString'和'custom'。
X = gamultiobj(FITNESSFCN,NVARS,A,b,Aeq,beq,lb,ub)定义设计变量X的下限和上限,以便在范围lb <= X <= ub中找到局部帕累托集。如果不存在边界,则使用空矩阵。如果X(i)无下限,则设置lb(i)= -Inf;如果X(i)无上限,则设置ub(i)= Inf。仅支持默认的PopulationType选项('doubleVector')的边界约束;不支持其他种群类型,例如'bitString'和'custom'。
X = gamultiobj(FITNESSFCN,NVARS,A,b,Aeq,beq,lb,ub,NONLCON)找到满足NONLCON中定义的约束的局部帕累托集X。函数NONLCON接受X并返回向量C和Ceq,分别表示非线性不等式和等式。帕累托集X必须满足C(X)<=0和Ceq(X)=0。如果不存在边界,则设置lb=[]和/或ub=[]。当PopulationType选项设置为'bitString'或'custom'时,不满足非线性约束。有关详细信息,请参见文档。
X = gamultiobj(FITNESSFCN,NVARS,A,b,Aeq,beq,lb,ub,NONLCON,options)使用OPTIONS中的值替换默认优化参数,找到帕累托集X。OPTIONS可以通过OPTIMOPTIONS函数创建。有关详细信息,请参见OPTIMOPTIONS。有关gamultiobj接受的选项列表,请参见文档。
X = gamultiobj(PROBLEM)查找PROBLEM的最小值。PROBLEM是具有以下字段的结构:
fitnessfcn:<Fitness function>
nvars:<Number of design variables>
Aineq:<不等式约束的A矩阵>
bineq:<不等式约束的b向量>
Aeq:<等式约束的Aeq矩阵>
beq:<等式约束的beq向量>
lb:<X的下限>
ub:<X的上限>
nonlcon:<非线性约束函数>
options:<使用optimoptions('gamultiobj',...)创建的选项>
solver:<solver name 'gamultiobj'>
rngstate:<随机数生成器的状态>
[X,FVAL] = gamultiobj(FITNESSFCN,NVARS,...)还返回矩阵FVAL,FITNESSFCN中定义的所有目标函数在X的所有解中的值。FVAL具有numberOfObjectives列,行数与X相同。
[X,FVAL,EXITFLAG] = gamultiobj(FITNESSFCN,NVARS,...)还返回描述gamultiobj的退出条件的EXITFLAG。EXITFLAG的可能值以及相应的退出条件为
1:在options.MaxStallGenerations代内帕累托集的扩展的平均值的值的变化小于options.FunctionTolerance。
0:超过最大代数。
-1:由输出或绘图函数终止优化。
-2:未找到可行点。
-5:超时。
[X,FVAL,EXITFLAG,OUTPUT] = gamultiobj(FITNESSFCN,NVARS,...)还返回带有以下字段的结构OUTPUT:
rngstate:<GA开始前随机数生成器的状态>
generations:<总代数,不包括HybridFcn迭代>
funccount:<函数评估的总数>
maxconstraint:<最大约束违规(如果有)>
message:<gamultiobj终止消息>
[X,FVAL,EXITFLAG,OUTPUT,POPULATION] = gamultiobj(FITNESSFCN,...)在终止时还返回最终POPULATION。
[X,FVAL,EXITFLAG,OUTPUT,POPULATION,SCORE] = gamultiobj(FITNESSFCN,...)在终止时还返回最终POPULATION的SCORE。
3 MATLAB程序实现
3.1 gamultiobj组织结构
3.2 函数stepgamultiobj分析
function parents = selectiontournament(expectation,nParents,options,tournamentSize)
if nargin < 4 || isempty(tournamentSize)
tournamentSize = 4;
end
% Choose the players
playerlist = ceil(size(expectation,1) * rand(nParents,tournamentSize));
% Play tournament
parents = tournament(playerlist,expectation);
function champions = tournament(playerlist,expectation)
%tournament between players based on their expectation
playerSize = size(playerlist,1);
champions = zeros(1,playerSize);
% For each set of players
for i = 1:playerSize
players = playerlist(i,:);
% For each tournament
winner = players(1); % Assume that the first player is the winner
for j = 2:length(players) % Winner plays against each other consecutively
score1 = expectation(winner,:);
score2 = expectation(players(j),:);
if score2(1) > score1(1)
winner = players(j);
elseif score2(1) == score1(1)
try % socre(2) may not be present for single objective problems
if score2(2) > score1(2)
winner = players(j);
end
catch
end
end
end
champions(i) = winner;
end
population=[population;nextPopulation];
3.3使用函数gamultiobj求解多目标优化问题
function f = my_first_multi(x)
f(1) = x(1)^4 - 10*x(1)^2+x(1)*x(2) + x(2)^4 - (x(1)^2)*(x(2)^2);
f(2) = x(2)^4 - (x(1)^2)*(x(2)^2) + x(1)^4 + x(1)*x(2);
clear
clc
fitnessfcn = @my_first_multi; % Function handle to the fitness function
nvars = 2; % Number of decision variables
lb = [-5,-5]; % Lower bound
ub = [5,5]; % Upper bound
A = []; b = []; % No linear inequality constraints
Aeq = []; beq = []; % No linear equality constraints
options = gaoptimset('ParetoFraction',0.3,'PopulationSize',100,'Generations',200,'StallGenLimit',200,'TolFun',1e-100,'PlotFcns',@gaplotpareto);
[x,fval] = gamultiobj(fitnessfcn,nvars, A,b,Aeq,beq,lb,ub,options);
3.4 结果分析
X1 | X2 | F1 | F2 |
-0.702604978119867 | 0.702952585998864 | -5.18650007950382 | -0.249962526715632 |
-0.702604978119867 | 0.702952585998864 | -5.18650007950382 | -0.249962526715632 |
-2.67029628249862 | 1.97094984179847 | -38.3329919666111 | 32.9718303966485 |
-2.63333082043443 | 1.96439479904977 | -38.2990862211675 | 31.0452258773312 |
-2.08276662583749 | 1.31511944032696 | -31.8120240265547 | 11.5671441504702 |
-1.15140918299647 | 0.929595004170188 | -12.9690674486452 | 0.288363618240700 |
-2.24644109783116 | 1.74843483243066 | -35.0074620102752 | 15.4575140499734 |
-2.41514714936595 | 1.79906399485147 | -37.0545025942865 | 21.2748549366181 |
-2.38150536923245 | 1.86154289865626 | -36.6275981206039 | 20.0880801162262 |
-1.82290570989828 | 1.23859537968056 | -27.1897975855276 | 6.04005468627002 |
-1.30683826246950 | 1.00106276130680 | -16.1770194512696 | 0.901242991273376 |
-2.51924521816231 | 1.97762256309168 | -37.6944252011462 | 25.7715394911906 |
-1.52418626573825 | 1.14877588640926 | -20.9096383290698 | 2.32179939758130 |
-1.06426303292729 | 0.940627721164028 | -11.2640394037852 | 0.0625186287707547 |
-2.03691502287105 | 1.46637748311609 | -31.5605834251883 | 9.92964467878934 |
-1.25902473471341 | 0.812532300017947 | -14.9724017318298 | 0.879031094371823 |
-2.54579676153300 | 1.91445377012727 | -38.0010331247212 | 26.8097783855977 |
-1.20396912943971 | 1.11637502706332 | -13.9916338566617 | 0.503782789776543 |
-2.48983479640961 | 1.85584414778789 | -37.6715458295670 | 24.3212273045537 |
-2.20516184528621 | 1.75854178206263 | -34.3335326972675 | 14.2938549417933 |
-2.01646480190617 | 1.57180853250172 | -31.2393168080679 | 9.42198616519718 |
-2.29454764988585 | 1.76104970025566 | -35.6807426169950 | 16.9687465589719 |
-1.45000820746889 | 1.40337975638453 | -18.9015806104910 | 2.12365740678036 |
-1.97425293081786 | 1.31617729318077 | -30.1344339638333 | 8.84231238459566 |
-1.74540792332427 | 1.19107078666463 | -25.5718188853058 | 4.89266930272549 |
-2.67029628249862 | 1.97094984179847 | -38.3329919666111 | 32.9718303966485 |
-0.903690328921961 | 0.874168873899340 | -8.32972021598921 | -0.163158110118390 |
-1.00010614649929 | 0.757833629162209 | -10.0042121434185 | -0.00208910076199753 |
-2.16416470915156 | 1.47815692188379 | -33.5583157841867 | 13.2777730991840 |
-2.57929181596638 | 1.94522918966795 | -38.1411557075827 | 28.3863070115286 |
从图5可以看到,第一前端的Pareto最优解分布均匀。从表1可以看到,返回的Pareto最优解个数为30个,而种群大小为100,可见,ParetoFraction为0.3的设置发挥了作用。另外,个体被限制在了[-5,5]的上下限范围内。