NSGAII源程序

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

functionf=crowding_distance(x,problem)%Thisfunctioncalculatesthecrowdingdistance[N,M]=size(x);switchproblemcase1M=2;V=6;case2M=3;V=12;end%Crowdingdistanceforeachfrontfori=1:length(F(front).f)y(i,:)=x(F(front).f(i),:);endfori=1:M[sorted(i).individual,sorted(i).index]=sort(y(:,V+i));distance(sorted(i).index(1)).individual=Inf;distance(sorted(i).index(length(sorted(i).index))).individual=Inf;end[num,len]=size(y);%Initializeallthedistanceofindividualsaszero.fori=1:Mforj=2:num-1distance(j).individual=0;endobjective(i).range=...sorted(i).individual(length(sorted(i).individual))-...sorted(i).individual(1);%Maximumandminimumobjectivesvaluefortheithobjectiveend%Caluclatethecrowdingdistanceforfrontone.fori=1:Mforj=2:num-1distance(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;endend/PREPublishedwithMATLAB®7.0functionf=genetic_operator(parent_chromosome,pro,mu,mum);%Thisfunctionisutilizedtoproduceoffspringsfromparentchromosomes.%Thegeneticoperatorscorssoverandmutationwhicharecarriedoutwith%slightmodificationsfromtheoriginaldesign.Formoreinformationread%thedocumentenclosed.[N,M]=size(parent_chromosome);switchprocase1M=2;V=6;case2M=3;V=12;endp=1;was_crossover=0;was_mutation=0;l_limit=0;u_limit=1;fori=1:Nifrand(1)0.9child_1=[];child_2=[];parent_1=round(N*rand(1));ifparent_11parent_1=1;endparent_2=round(N*rand(1));ifparent_21parent_2=1;endwhileisequal(parent_chromosome(parent_1,:),parent_chromosome(parent_2,:))parent_2=round(N*rand(1));ifparent_21parent_2=1;endendparent_1=parent_chromosome(parent_1,:);parent_2=parent_chromosome(parent_2,:);forj=1:V%SBX(SimulatedBinaryCrossover)%Generatearandomnumberu(j)=rand(1);ifu(j)=0.5bq(j)=(2*u(j))^(1/(mu+1));elsebq(j)=(1/(2*(1-u(j))))^(1/(mu+1));endchild_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_limitchild_1(j)=u_limit;elseifchild_1(j)l_limitchild_1(j)=l_limit;endifchild_2(j)u_limitchild_2(j)=u_limit;elseifchild_2(j)l_limitchild_2(j)=l_limit;endendchild_1(:,V+1:M+V)=evaluate_objective(child_1,pro);child_2(:,V+1:M+V)=evaluate_objective(child_2,pro);was_crossover=1;was_mutation=0;elseparent_3=round(N*rand(1));ifparent_31parent_3=1;end%Makesurethatthemutationdoesnotresultinvariablesoutof%thesearchspace.ForboththeMOP'stherangefordecisionspace%is[0,1].Incasedifferentvariableshavedifferentdecision%spaceeachvariablecanbeassignedarange.child_3=parent_chromosome(parent_3,:);forj=1:Vr(j)=rand(1);ifr(j)0.5delta(j)=(2*r(j))^(1/(mum+1))-1;elsedelta(j)=1-(2*(1-r(j)))^(1/(mum+1));endchild_3(j)=child_3(j)+delta(j);ifchild_3(j)u_limitchild_3(j)=u_limit;elseifchild_3(j)l_limitchild_3(j)=l_limit;endendchild_3(:,V+1:M+V)=evaluate_objective(child_3,pro);was_mutation=1;was_crossover=0;endifwas_crossoverchild(p,:)=child_1;child(p+1,:)=child_2;was_cossover=0;p=p+2;elseifwas_mutationchild(p,:)=child_3(1,1:M+V);was_mutation=0;p=p+1;endendf=child;PublishedwithMATLAB®7.0functionf=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;switchproblemcase1M=6;K=8;case2M=12;K=15;endfori=1:N%Initializethedecisionvariablesforj=1:Mf(i,j)=rand(1);%i.ef(i,j)=min+(max-min)*rand(1);end%Evaluatetheobjectivefunctionf(i,M+1:K)=evaluate_objective(f(i,:),problem);end/PREPublishedwithMATLAB®7.0Non-DonimationSortThisfunctionsortthecurrentpopultionbasedonnon-domination.Alltheindividualsinthefirstfrontaregivenarankof1,thesecondfrontindividualsareassignedrank2andsoon.Afterassigningtherankthecrowdingineachfrontiscalculated.[N,M]=size(x);switchproblemcase1M=2;V=6;case2M=3;V=12;endfront=1;%Thereisnothingtothisassignment,usedonlytomanipulateeasilyin%MATLAB.F(front).f=[];individual=[];fori=1:N%Numberofindividualsthatdominatethisindividualindividual(i).n=0;%Individualswhichthisindividualdominateindividual(i).p=[];forj=1:Ndom_less=0;dom_equal=0;dom_more=0;fork=1:Mif(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;elsedom_more=dom_more+1;endendifdom_less==0&dom_equal~=Mindividual(i).n=individual(i).n+1;elseifdom_more==0&dom_equal~=Mindividual(i).p=[individual(i).pj];endendifindividual(i).n==0x(i,M+V+1)=1;F(front).f=[F(front).fi];endend%Findthesubsequentfrontswhile~isempty(F(front).f)Q=[];fori=1:length(F(front).f)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==0x(individual(F(front).f(i)).p(j),M+V+1)=...front+1;Q=[Qind

1 / 15
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功