




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
最短路径问题的实现4.1 Dijkstra数组实现代码主程序部分close all;clear all;clc;W=zeros(5);index=1,2,3,4,5;W(1,2)=10;W(1,4)=30;W(1,5)=100;W(2,3)=50; W(3,5)=10;W(4,2)=10;W(4,3)=20;W(4,5)=60;for i=1:5 for j=1:5 if i=j & W(i,j)=0 W(i,j)=inf; end endendstart=1;S=start,zeros(1,4);D=index;W(S(1),:);for i=1:4 mid_1,min_1 =Get_min( S,D );S(1,i+1)=mid_1;mid_D=index;W(mid_1,:);D=Get_new(S,mid_D,D,min_1,index);end % S=1,1,1,2,3,4,4,4; % E=2,4,5,3,5,2,3,5; % W=10,30,100,50,10,10,20,60; % G(9,9)=0;% G=sparse(S,E,W); % G(5,5)=0;% P=biograph(G,ShowWeights,on);% H=view(P);% set(H.Nodes(Path),Color,1 0.4 0.4);% edges=getedgesbynodeid(H,get(H.Nodes(Path),ID);% set(edges,LineColor,1 0 0);% set(edges,LineWidth,2.0);函数部分function mid_index,min_D =Get_min( S,D) S=S(S=0); mid_D=D; mid_D(:,S)=; min_D=min(mid_D(2,:); ,mid_index=find(D=min_D); mid_index=min(mid_index); endfunction D = Get_new(S,mid_D,D,min_1,index) W=mid_D; S=S(S=0); col=setdiff(index,S); W(2,:)=W(2,:)+min_1; for i=1:col if W(2,i)2 & isnumeric(varargin1) D = varargin1; varargin(1) = ;end % read in optional PV input argumentsnvarargin = numel(varargin);if nvarargin if rem(nvarargin,2) = 1 error(message(bioinfo:graphshortestpath:IncorrectNumberOfArguments, mfilename); end okargs = method,directed,weights; for j=1:2:nvarargin-1 pname = vararginj; pval = vararginj+1; k = find(strncmpi(pname,okargs,numel(pname); if isempty(k) error(message(bioinfo:graphshortestpath:UnknownParameterName, pname); elseif length(k)1 error(message(bioinfo:graphshortestpath:AmbiguousParameterName, pname); else switch(k) case 1 % method algorithm = find(strncmpi(pval,algorithms,numel(pval); if isempty(algorithm) error(message(bioinfo:graphshortestpath:NotValidMethod, pval) elseif numel(algorithm)1 error(message(bioinfo:graphshortestpath:AmbiguousMethod, pval) end case 2 % directed directed = bioinfoprivate.opttf(pval,okargsk,mfilename); case 3 % weights W = pval(:); end end endend % call the mex implementation of the graph algorithmsif nargout1 if isempty(W) dist,pred = graphalgs(algorithmkeysalgorithm,debug_level,directed,G,S); else dist,pred = graphalgs(algorithmkeysalgorithm,debug_level,directed,G,S,W); endelse if isempty(W) dist = graphalgs(algorithmkeysalgorithm,debug_level,directed,G,S); else dist = graphalgs(algorithmkeysalgorithm,debug_level,directed,G,S,W); endend dist = dist(D); % calculate pathsif nargout1 path = graphpred2path(pred,D);end结果示例:随机生成的有向交通图:val = (1,2) 17 (1,3) 20 (2,4) 60 (3,4) 23 (2,5) 12 (4,5) 44 (3,6) 45 (4,6) 21 (4,7) 15 (5,7) 17 (4,8) 77 (6,8) 17 (6,9) 15 (7,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 小学生课件有趣的内容
- 玻璃钢制品工公司招聘笔试题库及答案
- 小学生课件库制作
- 原地浸出井场操作工基础技能培训手册
- 钛冶炼工安全教育培训手册
- 陶瓷雕刻工岗位实习报告
- 超重型汽车列车挂车工职业技能模拟试卷含答案
- 道路货运汽车驾驶员上岗证考试题库及答案
- 水生物病害防治员岗位实习报告
- 运输服务人员安全教育培训手册
- 《向军队学执行力》课件
- GB/T 17145-2024废矿物油回收与再生利用导则
- 网络营销的热点技术与趋势分析
- 普通高中生物学课程标准-(2024修订版)
- 《肥胖与疾病关系的》课件
- 新疆防沙治沙生态建设可行性研究报告
- 国家开放大学《社会调查方法》期末考试题库
- 煤矿掘进专业培训
- 中医体重管理
- 新生儿腹泻护理查房
- 病理全流程数字化系统项目需求
评论
0/150
提交评论