首页 MATL新编多旅行商问题源代码

MATL新编多旅行商问题源代码

举报
开通vip

MATL新编多旅行商问题源代码文件编码(TTU-UITID-GGBKT-POIU-WUUI-0089)MATL新编多旅行商问题源代码PAGEMATLAB多旅行商问题源代码functionvarargout=mtspf_ga(xy,dmat,salesmen,min_tour,pop_size,num_iter,show_prog,show_res)%MTSPF_GAFixedMultipleTravelingSalesmenProblem(M-TSP)GeneticAlgorithm(GA)%Findsa(near)optimalsolu...

MATL新编多旅行商问题源代码
文件编码(TTU-UITID-GGBKT-POIU-WUUI-0089)MATL新编多旅行商问题源代码PAGEMATLAB多旅行商问题源代码functionvarargout=mtspf_ga(xy,dmat,salesmen,min_tour,pop_size,num_iter,show_prog,show_res)%MTSPF_GAFixedMultipleTravelingSalesmenProblem(M-TSP)GeneticAlgorithm(GA)%Findsa(near)optimalsolutiontoavariationoftheM-TSPbysetting%upaGAtosearchfortheshortestroute(leastdistanceneededfor%eachsalesmantotravelfromthestartlocationtoindividualcities%andbacktotheoriginalstartingplace)%%Summary:%1.Eachsalesmanstartsatthefirstpoint,andendsatthefirst%point,buttravelstoauniquesetofcitiesinbetween%2.Exceptforthefirst,eachcityisvisitedbyexactlyonesalesman%%Note:TheFixedStart/EndlocationistakentobethefirstXYpoint%%Input:%XY(float)isanNx2matrixofcitylocations,whereNisthenumberofcities%DMAT(float)isanNxNmatrixofcity-to-citydistancesorcosts%SALESMEN(scalarinteger)isthenumberofsalesmentovisitthecities%MIN_TOUR(scalarinteger)istheminimumtourlengthforanyofthe%salesmen,NOTincludingthestart/endpoint%POP_SIZE(scalarinteger)isthesizeofthepopulation(shouldbedivisibleby8)%NUM_ITER(scalarinteger)isthenumberofdesirediterationsforthealgorithmtorun%SHOW_PROG(scalarlogical)showstheGAprogressiftrue%SHOW_RES(scalarlogical)showstheGAresultsiftrue%%Output:%OPT_RTE(integerarray)isthebestroutefoundbythealgorithm%OPT_BRK(integerarray)isthelistofroutebreakpoints(thesespecifytheindices%intotherouteusedtoobtaintheindividualsalesmanroutes)%MIN_DIST(scalarfloat)isthetotaldistancetraveledbythesalesmen%%Route/BreakpointDetails:%Ifthereare10citiesand3salesmen,apossibleroute/break%combinationmightbe:rte=[5694281037],brks=[37]%Takentogether,theserepresentthesolution[15691][14281][110371],%whichdesignatestheroutesforthe3salesmenasfollows:%.Salesman1travelsfromcity1to5to6to9andbackto1%.Salesman2travelsfromcity1to4to2to8andbackto1%.Salesman3travelsfromcity1to10to3to7andbackto1%%2DExample:%n=35;%xy=10*rand(n,2);%salesmen=5;%min_tour=3;%pop_size=80;%num_iter=5e3;%a=meshgrid(1:n);%dmat=reshape(sqrt(sum((xy(a,:)-xy(a',:)).^2,2)),n,n);%[opt_rte,opt_brk,min_dist]=mtspf_ga(xy,dmat,salesmen,min_tour,...%pop_size,num_iter,1,1);%%3DExample:%n=35;%xyz=10*rand(n,3);%salesmen=5;%min_tour=3;%pop_size=80;%num_iter=5e3;%a=meshgrid(1:n);%dmat=reshape(sqrt(sum((xyz(a,:)-xyz(a',:)).^2,2)),n,n);%[opt_rte,opt_brk,min_dist]=mtspf_ga(xyz,dmat,salesmen,min_tour,...%pop_size,num_iter,1,1);%%Seealso:mtsp_ga,mtspo_ga,mtspof_ga,mtspofs_ga,mtspv_ga,distmat%%Author:JosephKirk%Email%Release:%ReleaseDate:6/2/09%ProcessInputsandInitializeDefaultsnargs=8;fork=nargin:nargs-1switchkcase0xy=10*rand(40,2);case1N=size(xy,1);a=meshgrid(1:N);dmat=reshape(sqrt(sum((xy(a,:)-xy(a',:)).^2,2)),N,N);case2salesmen=5;case3min_tour=2;case4pop_size=80;case5num_iter=5e3;case6show_prog=1;case7show_res=1;otherwiseendend%VerifyInputs[N,dims]=size(xy);[nr,nc]=size(dmat);ifN~=nr||N~=ncerror('InvalidXYorDMATinputs!')endn=N-1;%SeparateStart/EndCity%SanityCheckssalesmen=max(1,min(n,round(real(salesmen(1)))));min_tour=max(1,min(floor(n/salesmen),round(real(min_tour(1)))));pop_size=max(8,8*ceil(pop_size(1)/8));num_iter=max(1,round(real(num_iter(1))));show_prog=logical(show_prog(1));show_res=logical(show_res(1));%InitializationsforRouteBreakPointSelectionnum_brks=salesmen-1;dof=n-min_tour*salesmen;%degreesoffreedomaddto=ones(1,dof+1);fork=2:num_brksaddto=cumsum(addto);endcum_prob=cumsum(addto)/sum(addto);%InitializethePopulationspop_rte=zeros(pop_size,n);%populationofroutespop_brk=zeros(pop_size,num_brks);%populationofbreaksfork=1:pop_sizepop_rte(k,:)=randperm(n)+1;pop_brk(k,:)=randbreaks();end%SelecttheColorsforthePlottedRoutesclr=[100;001;01;010;10];ifsalesmen>5clr=hsv(salesmen);end%RuntheGAglobal_min=Inf;total_dist=zeros(1,pop_size);dist_history=zeros(1,num_iter);tmp_pop_rte=zeros(8,n);tmp_pop_brk=zeros(8,num_brks);new_pop_rte=zeros(pop_size,n);new_pop_brk=zeros(pop_size,num_brks);ifshow_progpfig=figure('Name','MTSPF_GA|CurrentBestSolution','Numbertitle','off');endforiter=1:num_iter%EvaluateMembersofthePopulationforp=1:pop_sized=0;p_rte=pop_rte(p,:);p_brk=pop_brk(p,:);rng=[[1p_brk+1];[p_brkn]]';fors=1:salesmend=d+dmat(1,p_rte(rng(s,1)));%AddStartDistancefork=rng(s,1):rng(s,2)-1d=d+dmat(p_rte(k),p_rte(k+1));endd=d+dmat(p_rte(rng(s,2)),1);%AddEndDistanceendtotal_dist(p)=d;end%FindtheBestRouteinthePopulation[min_dist,index]=min(total_dist);dist_history(iter)=min_dist;ifmin_dist
本文档为【MATL新编多旅行商问题源代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
个人认证用户
东红
暂无简介~
格式:doc
大小:143KB
软件:Word
页数:0
分类:企业经营
上传时间:2021-10-24
浏览量:1