NSGAII源程序Word格式文档下载.docx

上传人:b****5 文档编号:18142589 上传时间:2022-12-13 格式:DOCX 页数:17 大小:19.53KB
下载 相关 举报
NSGAII源程序Word格式文档下载.docx_第1页
第1页 / 共17页
NSGAII源程序Word格式文档下载.docx_第2页
第2页 / 共17页
NSGAII源程序Word格式文档下载.docx_第3页
第3页 / 共17页
NSGAII源程序Word格式文档下载.docx_第4页
第4页 / 共17页
NSGAII源程序Word格式文档下载.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

NSGAII源程序Word格式文档下载.docx

《NSGAII源程序Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《NSGAII源程序Word格式文档下载.docx(17页珍藏版)》请在冰豆网上搜索。

NSGAII源程序Word格式文档下载.docx

objective(i).range=...

sorted(i).individual(length(sorted(i).individual))-...

sorted(i).individual

(1);

%Maximumandminimumobjectivesvaluefortheithobjective

%Caluclatethecrowdingdistanceforfrontone.

distance(j).individual=distance(j).individual+...

(sorted(i).individual(j+1)-sorted(i).individual(j-1))/...

objective(i).range;

y(sorted(i).index(j),M+V+2)=distance(j).individual;

<

/PRE

PublishedwithMATLAB®

7.0

functionf=genetic_operator(parent_chromosome,pro,mu,mum);

%Thisfunctionisutilizedtoproduceoffspringsfromparentchromosomes.

%Thegeneticoperatorscorssoverandmutationwhicharecarriedoutwith

%slightmodificationsfromtheoriginaldesign.Formoreinformationread

%thedocumentenclosed.

[N,M]=size(parent_chromosome);

switchpro

p=1;

was_crossover=0;

was_mutation=0;

l_limit=0;

u_limit=1;

N

ifrand

(1)<

0.9

child_1=[];

child_2=[];

parent_1=round(N*rand

(1));

ifparent_1<

1

parent_1=1;

parent_2=round(N*rand

(1));

ifparent_2<

parent_2=1;

whileisequal(parent_chromosome(parent_1,:

),parent_chromosome(parent_2,:

))

parent_1=parent_chromosome(parent_1,:

parent_2=parent_chromosome(parent_2,:

forj=1:

V

%SBX(SimulatedBinaryCrossover)

%Generatearandomnumber

u(j)=rand

(1);

ifu(j)<

=0.5

bq(j)=(2*u(j))^(1/(mu+1));

else

bq(j)=(1/(2*(1-u(j))))^(1/(mu+1));

child_1(j)=...

0.5*(((1+bq(j))*parent_1(j))+(1-bq(j))*parent_2(j));

child_2(j)=...

0.5*(((1-bq(j))*parent_1(j))+(1+bq(j))*parent_2(j));

ifchild_1(j)>

u_limit

child_1(j)=u_limit;

elseifchild_1(j)<

l_limit

child_1(j)=l_limit;

ifchild_2(j)>

child_2(j)=u_limit;

elseifchild_2(j)<

child_2(j)=l_limit;

child_1(:

V+1:

M+V)=evaluate_objective(child_1,pro);

child_2(:

M+V)=evaluate_objective(child_2,pro);

was_crossover=1;

was_mutation=0;

parent_3=round(N*rand

(1));

ifparent_3<

parent_3=1;

%Makesurethatthemutationdoesnotresultinvariablesoutof

%thesearchspace.ForboththeMOP'

stherangefordecisionspace

%is[0,1].Incasedifferentvariableshavedifferentdecision

%spaceeachvariablecanbeassignedarange.

child_3=parent_chromosome(parent_3,:

r(j)=rand

(1);

ifr(j)<

0.5

delta(j)=(2*r(j))^(1/(mum+1))-1;

delta(j)=1-(2*(1-r(j)))^(1/(mum+1));

child_3(j)=child_3(j)+delta(j);

ifchild_3(j)>

child_3(j)=u_limit;

elseifchild_3(j)<

child_3(j)=l_limit;

child_3(:

M+V)=evaluate_objective(child_3,pro);

was_mutation=1;

was_crossover=0;

ifwas_crossover

child(p,:

)=child_1;

child(p+1,:

)=child_2;

was_cossover=0;

p=p+2;

elseifwas_mutation

)=child_3(1,1:

M+V);

p=p+1;

f=child;

PublishedwithMATLAB®

functionf=initialize_variables(N,problem)

%functionf=initialize_variables(N,problem)

%N-Populationsize

%problem-takesintegervalues1and2where,

%'

1'

forMOP1

2'

forMOP2

%

%ThisfunctioninitializesthepopulationwithNindividualsandeach

%individualhavingMdecisionvariablesbasedontheselectedproblem.

%M=6forproblemMOP1andM=12forproblemMOP2.Theobjectivespace

%forMOP1is2dimensionalwhileforMOP2is3dimensional.

%BoththeMOP'

shas0to1asitsrangeforallthedecisionvariables.

min=0;

max=1;

M=6;

K=8;

M=12;

K=15;

%Initializethedecisionvariables

f(i,j)=rand

(1);

%i.ef(i,j)=min+(max-min)*rand

(1);

%Evaluatetheobjectivefunction

f(i,M+1:

K)=evaluate_objective(f(i,:

),problem);

Non-DonimationSort

Thisfunctionsortthecurrentpopultionbasedonnon-domination.Alltheindividualsinthefirstfrontaregivenarankof1,thesecondfrontindividualsareassignedrank2andsoon.Afterassigningtherankthecrowdingineachfrontiscalculated.

front=1;

%Thereisnothingtothisassignment,usedonlytomanipulateeasilyin

%MATLAB.

F(front).f=[];

individual=[];

%Numberofindividualsthatdominatethisindividual

individual(i).n=0;

%Individualswhichthisindividualdominate

individual(i).p=[];

dom_less=0;

dom_equal=0;

dom_more=0;

fork=1:

if(x(i,V+k)<

x(j,V+k))

dom_less=dom_less+1;

elseif(x(i,V+k)==x(j,V+k))

dom_equal=dom_equal+1;

dom_more=dom_more+1;

ifdom_less==0&

dom_equal~=M

individual(i).n=individual(i).n+1;

elseifdom_more==0&

individual(i).p=[individual(i).pj];

ifindividual(i).n==0

x(i,M+V+1)=1;

F(front).f=[F(front).fi];

%Findthesubsequentfronts

while~isempty(F(front).f)

Q=[];

fori=1:

if~isempty(individual(F(front).f(i)).p)

forj=1:

length(individual(F(front).f(i)).p)

individual(individual(F(front).f(i)).p(j)).n=...

individual(individual(F(front).f(i)).p(j)).n-1;

ifindividual(individual(F(front).f(i)).p(j)).n==0

x(individual(F(front).f(i)).p(j),M+V+1)=...

front+1;

Q=[Qindividual(F(front).f(i)).p(j)];

front=front+1;

F(front).f=Q;

[temp,index_of_fronts]=sort(x(:

M+V+1));

length(index_of_fronts)

sorted_based_on_front(i,:

)=x(index_of_fronts(i),:

current_index=0;

%Findthecrowdingdistanceforeachindividualineachfront

forfront=1:

(length(F)-1)

objective=[];

distance=0;

y=[];

previous_index=current_index+1;

)=sorted_based_on_front(current_index+i,:

current_index=current_index+i;

%Sorteachindividualbasedontheobjective

sorted_based_on_objective=[];

[sorted_based_on_objective,index_of_objectives]=...

sort(y(:

length(index_of_objectives)

sorted_based_on_objective(j,:

)=y(index_of_objectives(j),:

f_max=...

sorted_based_on_objective(length(index_of_objectives),V+i);

f_min=sorted_based_on_objective(1,V+i);

y(index_of_objectives(length(index_of_objectives)),M+V+1+i)...

=Inf;

y(index_of_objectives

(1),M+V+1+i)=Inf;

length(index_of_objectives)-1

next_obj=sorted_based_on_objective(j+1,V+i);

previous_obj=sorted_based_on_objective(j-1,V+i);

if(f_max-f_min==0)

y(index_of_objectives(j),M+V+1+i)=Inf;

y(index_of_objectives(j),M+V+1+i)=...

(next_obj-previous_obj)/(f_max-f_min);

distance=[];

distance(:

1)=zeros(length(F(front).f),1);

1)=distance(:

1)+y(:

M+V+1+i);

y(:

M+V+2)=distance;

y=y(:

1:

M+V+2);

z(previous_index:

current_index,:

)=y;

f=z();

MainFunction

MainprogramtoruntheNSGA-IIMOEA.Readthecorrespondingdocumentationtolearnmoreaboutmultiobjectiveoptimizationusingevolutionaryalgorithms.initialize_variableshastwoarguments;

Firstbeingthepopulationsizeandthesecondtheproblemnumber.'

correspondstoMOP1and'

correspondstoMOP2.

Contents

∙Initializethevariables

∙Sorttheinitializedpopulation

∙Starttheevolutionprocess

∙Result

∙Visualize

Initializethevariables

Declarethevariablesandinitializetheirvaluespop-populationgen-generationspro-problemnumber

pop=200;

gen=1;

pro=1;

%Misthenumberofobjectives.

%Visthenumberofdecisionvariables.Inthiscaseitis

%difficulttovisualizethedecisionvariablesspacewhilethe

%objectivespaceisjusttwodimensional.

%Initializethepopulation

chromosome=initialize_variables(pop,pro);

Sorttheinitializedpopulation

Sortthepopulationusingnon-domination-sort.Thisreturnstwocolumnsforeachindividualwhicharetherankandthecrowdingdistancecorrespondingtotheirpositioninthefronttheybelong.

chromosome=non_domination_sort_mod(chromosome,pro);

Starttheevolutionprocess

%Thefollowingareperformedineachgeneration

%Selecttheparents

%PerfromcrossoverandMutationoperator

%PerformSelection

gen

%Selecttheparents

%Parentsareselectedforreproductiontogenerateoffspring.The

%originalNSGA-IIusesabinarytournamentselectionbasedonthe

%crowded-comparisionoperator.Theargumentsare

%pool-sizeofthematingpool.Itiscommontohavethistobehalfthe

%populationsize.

%tour-Tournamentsiz

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1