Вы находитесь на странице: 1из 5

12/16/2015

PerformingaMultiobjectiveOptimizationUsingtheGeneticAlgorithmMATLAB&SimulinkExampleMathWorksIndia

PerformingaMultiobjectiveOptimizationUsingthe
GeneticAlgorithm
Thisexampleshowshowtoperformamultiobjectiveoptimizationusingmultiobjectivegenetic
algorithmfunctiongamultiobjinGlobalOptimizationToolbox.

SimpleMultiobjectiveOptimizationProblem

CodingtheFitnessFunction

MinimizingUsinggamultiobj

ConstrainedMultiobjectiveOptimizationProblem

AddingVisualization

VectorizingYourFitnessFunction

OpenThisExample

SimpleMultiobjectiveOptimizationProblem
gamultiobjcanbeusedtosolvemultiobjectiveoptimizationprobleminseveralvariables.Herewewanttominimizetwo
objectives,eachhavingonedecisionvariable.
minF(x)=[objective1(x);objective2(x)]
x
where,objective1(x)=(x+2)^210,and
objective2(x)=(x2)^2+20
%Plottwoobjectivefunctionsonthesameaxis
x=10:0.5:10;
f1=(x+2).^210;
f2=(x2).^2+20;
plot(x,f1);
holdon;
plot(x,f2,'r');
gridon;
title('Plotofobjectives''(x+2)^210''and''(x2)^2+20''');

http://in.mathworks.com/help/gads/examples/performingamultiobjectiveoptimizationusingthegeneticalgorithm.html#zmw57dd0e2368

1/5

12/16/2015

PerformingaMultiobjectiveOptimizationUsingtheGeneticAlgorithmMATLAB&SimulinkExampleMathWorksIndia

Thetwoobjectiveshavetheirminimaatx=2andx=+2respectively.However,inamultiobjectiveproblem,x=2,x=2,
andanysolutionintherange2<=x<=2isequallyoptimal.Thereisnosinglesolutiontothismultiobjectiveproblem.
Thegoalofthemultiobjectivegeneticalgorithmistofindasetofsolutionsinthatrange(ideallywithagoodspread).The
setofsolutionsisalsoknownasaParetofront.AllsolutionsontheParetofrontareoptimal.

CodingtheFitnessFunction
WecreateaMATLABfilenamedsimple_multiobjective.m:
functiony=simple_multiobjective(x)
y(1)=(x+2)^210;
y(2)=(x2)^2+20;
TheGeneticAlgorithmsolverassumesthefitnessfunctionwilltakeoneinputx,wherexisarowvectorwithasmany
elementsasthenumberofvariablesintheproblem.Thefitnessfunctioncomputesthevalueofeachobjectivefunction
andreturnsthesevaluesinasinglevectoroutputy.

MinimizingUsinggamultiobj
Tousethegamultiobjfunction,weneedtoprovideatleasttwoinputarguments,afitnessfunction,andthenumberof
variablesintheproblem.ThefirsttwooutputargumentsreturnedbygamultiobjareX,thepointsonParetofront,and
FVAL,theobjectivefunctionvaluesatthevaluesX.Athirdoutputargument,exitFlag,tellsyouthereasonwhy
gamultiobjstopped.Afourthargument,OUTPUT,containsinformationabouttheperformanceofthesolver.gamultiobj
canalsoreturnafifthargument,POPULATION,thatcontainsthepopulationwhengamultiobjterminatedandasixth
argument,SCORE,thatcontainsthefunctionvaluesofallobjectivesforPOPULATIONwhengamultiobjterminated.
FitnessFunction=@simple_multiobjective;
numberOfVariables=1;
[x,fval]=gamultiobj(FitnessFunction,numberOfVariables);
Optimizationterminated:averagechangeinthespreadofParetosolutionslessthanoptions.TolFun.
TheXreturnedbythesolverisamatrixinwhicheachrowisthepointontheParetofrontfortheobjectivefunctions.The
FVALisamatrixinwhicheachrowcontainsthevalueoftheobjectivefunctionsevaluatedatthecorrespondingpointinX.
size(x)
size(fval)
http://in.mathworks.com/help/gads/examples/performingamultiobjectiveoptimizationusingthegeneticalgorithm.html#zmw57dd0e2368

2/5

12/16/2015

PerformingaMultiobjectiveOptimizationUsingtheGeneticAlgorithmMATLAB&SimulinkExampleMathWorksIndia

ans=
181

ans=
182

ConstrainedMultiobjectiveOptimizationProblem
gamultiobjcanhandleoptimizationproblemswithlinearinequality,equality,andsimpleboundconstraints.Herewe
wanttoaddboundconstraintsonsimplemultiobjectiveproblemsolvedpreviously.
minF(x)=[objective1(x);objective2(x)]
x
subjectto1.5<=x<=0(boundconstraints)
where,objective1(x)=(x+2)^210,and
objective2(x)=(x2)^2+20
gamultiobjacceptslinearinequalityconstraintsintheformA*x<=bandlinearequalityconstraintsintheformAeq*x=
beqandboundconstraintsintheformlb<x<ub.WepassAandAeqasmatricesandb,beq,lb,andubasvectors.Since
wehavenolinearconstraintsinthisexample,wepass[]forthoseinputs.
A=[];b=[];
Aeq=[];beq=[];
lb=1.5;
ub=0;
x=gamultiobj(FitnessFunction,numberOfVariables,A,b,Aeq,beq,lb,ub);
Optimizationterminated:maximumnumberofgenerationsexceeded.
AllsolutionsinX(eachrow)willsatisfyalllinearandboundconstraintswithinthetolerancespecifiedinoptions.TolCon.
However,ifyouuseyourowncrossoverormutationfunction,ensurethatthenewindividualsarefeasiblewithrespectto
linearandsimpleboundconstraints.

AddingVisualization
gamultiobjcanacceptoneormoreplotfunctionsthroughtheoptionsargument.Thisfeatureisusefulforvisualizingthe
performanceofthesolveratruntime.Plotfunctionscanbeselectedusinggaoptimset.Thehelpforgaoptimsetcontains
alistofplotfunctionstochoosefrom.
Hereweusegaoptimsettocreateanoptionsstructuretoselecttwoplotfunctions.Thefirstplotfunctionis
GAPLOTPARETO,whichplotstheParetofront(limitedtoanythreeobjectives)ateverygeneration.Thesecondplot
functionisGAPLOTSCOREDIVERSITY,whichplotsthescorediversityforeachobjective.Theoptionsstructureispassed
asthelastargumenttothesolver.
options=gaoptimset('PlotFcns',{@gaplotpareto,@gaplotscorediversity});
gamultiobj(FitnessFunction,numberOfVariables,[],[],[],[],lb,ub,options);
Optimizationterminated:maximumnumberofgenerationsexceeded.

http://in.mathworks.com/help/gads/examples/performingamultiobjectiveoptimizationusingthegeneticalgorithm.html#zmw57dd0e2368

3/5

12/16/2015

PerformingaMultiobjectiveOptimizationUsingtheGeneticAlgorithmMATLAB&SimulinkExampleMathWorksIndia

VectorizingYourFitnessFunction
Considerthepreviousfitnessfunctionsagain:
objective1(x)=(x+2)^210,and
objective2(x)=(x2)^2+20
Bydefault,thegamultiobjsolveronlypassesinonepointatatimetothefitnessfunction.However,ifthefitnessfunction
isvectorizedtoacceptasetofpointsandreturnsasetoffunctionvaluesyoucanspeedupyoursolution.
Forexample,ifthesolverneedstoevaluatefivepointsinonecalltothisfitnessfunction,thenitwillcallthefunctionwitha
matrixofsize5by1,i.e.,5rowsand1column(recallthat1isthenumberofvariables).
CreateaMATLABfilecalledvectorized_multiobjective.m:
functionscores=vectorized_multiobjective(pop)
popSize=size(pop,1);%Populationsize
numObj=2;%Numberofobjectives
%initializescores
scores=zeros(popSize,numObj);
%Computefirstobjective
scores(:,1)=(pop+2).^210;
%Computesecondobective
scores(:,2)=(pop2).^2+20;
Thisvectorizedversionofthefitnessfunctiontakesamatrix'pop'withanarbitrarynumberofpoints,therowsof'pop',and
returnsamatrixofsizepopulationSizebynumberOfObjectives.
Weneedtospecifythatthefitnessfunctionisvectorizedusingtheoptionsstructurecreatedusinggaoptimset.The
optionsstructureispassedinastheninthargument.
FitnessFunction=@(x)vectorized_multiobjective(x);
options=gaoptimset('Vectorized','on');
gamultiobj(FitnessFunction,numberOfVariables,[],[],[],[],lb,ub,options);
Optimizationterminated:averagechangeinthespreadofParetosolutionslessthanoptions.TolFun.
http://in.mathworks.com/help/gads/examples/performingamultiobjectiveoptimizationusingthegeneticalgorithm.html#zmw57dd0e2368

4/5

12/16/2015

PerformingaMultiobjectiveOptimizationUsingtheGeneticAlgorithmMATLAB&SimulinkExampleMathWorksIndia

http://in.mathworks.com/help/gads/examples/performingamultiobjectiveoptimizationusingthegeneticalgorithm.html#zmw57dd0e2368

5/5

Вам также может понравиться