求解最大流问题的matlab程序Matlab program for solving maximum flow problems.docx
- 文档编号:25135347
- 上传时间:2023-06-05
- 格式:DOCX
- 页数:7
- 大小:16.13KB
求解最大流问题的matlab程序Matlab program for solving maximum flow problems.docx
《求解最大流问题的matlab程序Matlab program for solving maximum flow problems.docx》由会员分享,可在线阅读,更多相关《求解最大流问题的matlab程序Matlab program for solving maximum flow problems.docx(7页珍藏版)》请在冰豆网上搜索。
求解最大流问题的matlab程序Matlabprogramforsolvingmaximumflowproblems
求解最大流问题的matlab程序(Matlabprogramforsolvingmaximumflowproblems)
Maximumflowalgorithm
Algorithmidea:
themaximumflowproblemisactuallyafeasibleflow{fij},whichmakestheV(f)reachthemaximum.IfyougiveafeasibleflowF,aslongasthereisnojudgmentinNaugmentingpathontheF,ifthereisanaugmentedpath,improvedF,anewfeasibleflowrateincreases;ifthereisnoaugmentingpath,getthemaximumflow.
1.labelingmethodformaximumflow(Ford,Fulkerson)
Startingwithafeasibleflow(ageneralzeroflow),thefollowinglabelingprocedureandtheadjustmentprocessarefolloweduntilnoaugmentingpathaboutFcanbefound.
(1)labelingprocess
Inthisprocess,thepointsinthenetworkaredividedintolabeledandunlabeledpoints,andthelabeledpointsaredividedintotwokinds:
checkedandunchecked.Eachlabellabelinformationpointsareexpressedintwoparts:
thefirstlabelshowthatthelabelfromwhichpointtostartthetracebackpathfromtheVTtofindoutisaugmented;secondlabelissaidtohavecheckedwhetherthevertex.
Atthestartofthelabel,markvs(s,0),whenvsisthelabel,butattheendofthecheckpoint,andtherestareunlabeledpoints,denotedas(0,0).
TakealabelwithoutcheckingthepointVI,forallunlabeledpoints,vj:
A.forarc(VI,VJ),iffij B.forarc(VI,VJ),iffji>0,thengivetheVJlabel(-vi,0),thentheVJpointbecomesthelabel,whichisnotchecked. Thus,VIbecomesalabeledandcheckedpoint,anditssecondlabelisdenotedas1.Repeatthestepsaboveand,onceVTismarked,indicateanextendedpathfromVItoP,andVTintotheadjustmentprocess. Ifallthelabelshavebeencheckedandthelabelprocessfails,thealgorithmendswiththefeasibleflowbeingthemaximumflow. (2)adjustmentprocess FromtheVTpoint,throughthefirstlabelofeachpoint,backwardtracing,wecanfindtheaugmentingpathP.Forexample,ifthefirstlabelofVTisVK(or-vk),thenthearc(VK,VT)(orcorrespondingly(VT,VK))isthearcontheP.Next,checkthefirstlabelofVK,andifitisVI(or-vi),find(VI,VK)(orVI(VK)).CheckthefirstlabelofVI,andsoon,untilvs.Atthispoint,theentireaugmentingpathisfound.CalculatetheQatthesametimeasyoulookfortheaugmentingpath: Q=min{min(cij-fij),minf*ij} Convectivefissubjecttothefollowingmodifications: F'ij=fij+Q(VI,VJ)setpriortothearcinP's F'ij=fij-Q(VI,VJ)andPtoarcset F'ij=f*ij(VI,VJ)doesnotbelongtothesetofP Next,alltagsareclearedandthenewfeasiblestream'f'isreenteredintothelabelingprocess. Matlabproceduresforsolvingthemaximumflowproblem.(2007-05-2219: 41: 06)reprintlabel: maximumflowproblemmatlab Callway: needtobeabstractedintographmatrix,abstractmethods: (I,J,C,f)i---nock,j---arrow,c---v(I,J)thecapacityoff---v(I,J)oftheflow. mainprogram FunctionR=maxliu(R) While (1) VV=zengguang(R); IfVV==infreturn;end R(VV (1),4)=R(VV( (1))4)+VV( (2)*min)(VV((: : 3)); End Theouterfunction1,theexpansionmatrixofthegraphR FunctionVV=zengguang(R)%fortheshortestextensionchain,requiringlabeling,startingat1,andendingatthemaximum K=size(R,1); N=max(R((: : 2)); B=R(: : 1: 2); Fori=1: k; A(I,1)=R(I,3)-R(I,4); IfR(I,1)~=1&&R(I,2)~=n; A(I,2)=R(I,4); Else A(I,2)=0; End End R=1; Fori=1: n Forj=1: k If(A(J,1)(~=0)andB(J,1)==i) V(R: : )=[i,B(J,2)]; r=r+1. end if(i)=0)&&(b,i,2)==1) v(r)=(1,b),(d) (1); r=r+1. end end end p=zeros(n,n). fori=1: size(v,1) p(v(i,1),v(i,2))=1. end q=dijkstra(p,1,n). ifq=inf(vv=inf);return;end fori=1: length(q) (1). pi=(q(1,i),q(1,i+1)]; r1=find(b (1)=p (1)); r2=find(b (2)=p (1)); rr=intersect(r1,r2). d=1. theisempty()(rr) r1=find(b (1)=p (1)); r2=find(b (2)=p (1)); rr=intersect(r1,r2). d=-1. end (i)=rr. -(i)=-. end fori=1: size(vv.1) ifit(i)==1) aa(i,1)=((i,1), (1); end ifit(i)==1) aa(i,1)=((i,1), (2); end end (: 2)=tt. vv: (3)=sa; 外部函数2,dijkstra方法求最段路. thefoot=dijkstra(v,x,y)%正权数 m=size(v,1). t=zeros(m,1);%t的初始化inf t=t^-1. dml=;%lmd的初始化inf p=t;%p的初始化inf s=zeros(n,1);%s的初始化(进入s集的点为1) s(x)=1);%根据本题已知的初始化 p(x)=0(x)=0,;french; k=x; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%计算p " (1) a=find(s=0). aa=find(s=1). thesize(a,1)=m break; end fori=1: size(a,1) pi=(i,1). ifv(k,l)=0. ift(pp)(p(k)+v(k,l). (p)=(p(k)+v(k,l). dml(pi)=k; end end end mi=min(t(a)); ifmi=inf break; else d=find(t=e). d=d (1); p(d)=mi. (d)=inf,为了避免同样的数字出现两次. k=d (d)=1. end end themdl(y)=inf foot=inf. return; end foot (1). g=2;m=y; " (1) ifh=xxxxxxx break; end frenchfootball(g)=(h). g=g+1. h=(h);mdl end pace=foot); fori=1: length(foot) foot(1,i)= (1)/length(foot)+1(i). end
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 求解最大流问题的matlab程序Matlab program for solving maximum flow problems 求解 最大 问题 matlab 程序
链接地址:https://www.bdocx.com/doc/25135347.html