楼主: 996hjhj
7000 3

[程序分享] 求网络最短路径dijkstra算法的三个不同程序 [推广有奖]

  • 0关注
  • 4粉丝

已卖:1047份资源

讲师

40%

还不是VIP/贵宾

-

威望
0
论坛币
8310 个
通用积分
1.9391
学术水平
24 点
热心指数
28 点
信用等级
21 点
经验
58195 点
帖子
507
精华
0
在线时间
205 小时
注册时间
2010-8-14
最后登录
2015-5-4

楼主
996hjhj 发表于 2012-10-26 23:21:47 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
具体程序见附件

程序一:
%求网络最短路径的dijkstra算法
%用法:
% 首先输入矩阵:
%  map=[起点1 终点1 边长1;起点2 终点2  边长2;............;起点n 终点n 边长n]
%  和u1,u2
%  注意:这里map为无向图。
% 再用[p,v]=dijkstra(map,u1,u2)求最短路径
%参数说明
% map----3列邻接矩阵,每行表示一条边.
%         第一列表示起点,第二列表示终点,第三列表示边长
% u1---所求路径起点
% u2---所求路径终点
%   p---输出最短路径
%   v---最短路径的总长度
%例如  
%map=[1 2 6;1 3 1;2 3 6;2 4 3;2 5 4;2 6 1;3 5 2;3 6 7;4 5 5;5 6 2];
%  [p,v]=dijkstra(map,2,5)
%
%本算法调用由VC++6.0程序dijk.c生成的MEX文件dijk.dll求得最短路径
% 表示无穷大的数值上界(默认10000)
%
%See also KRUSKAL,LPINT,DP,BNBGUI,BNB18

程序二:
%图与网络论中求最短路径的Dijkstra算法 M-函数
%格式 [S,D]=minroute(i,m,W)
%    i为最短路径的起始点,m为图顶点数,W为图的带权邻接矩阵,
%    不构成边的两顶点之间的权用inf表示。显示结果为:S的每
%    一列从上到下记录了从始点到终点的最短路径所经顶点的序号;
%    D是一行向量,记录了S中所示路径的大小;
%例如
%    clear;w=inf*ones(6);w(1,3)=10;w(1,5)=30;
%    w(1,6)=100;w(2,3)=5;w(3,4)=50;w(4,6)=10;
%    w(5,4)=20;w(5,6)=60;
%    i=1;[s,d]=minroute(i,6,w)

程序三:
%DIJKSTRA Calculates the shortest distance and path between points on a map
%   using Dijkstra's Shortest Path Algorithm
%
% [DIST, PATH] = DIJKSTRA(NODES, SEGMENTS, SID, FID)
%   Calculates the shortest distance and path between start and finish nodes SID and FID
%
% [DIST, PATH] = DIJKSTRA(NODES, SEGMENTS, SID)
%   Calculates the shortest distances and paths from the starting node SID to all
%     other nodes in the map
%
% Note:
%     DIJKSTRA is set up so that an example is created if no inputs are provided,
%       but ignores the example and just processes the inputs if they are given.
%
% Inputs:
%     NODES should be an Nx3 or Nx4 matrix with the format [ID X Y] or [ID X Y Z]
%       where ID is an integer, and X, Y, Z are cartesian position coordinates)
%     SEGMENTS should be an Mx3 matrix with the format [ID N1 N2]
%       where ID is an integer, and N1, N2 correspond to node IDs from NODES list
%       such that there is an [undirected] edge/segment between node N1 and node N2
%     SID should be an integer in the node ID list corresponding with the starting node
%     FID (optional) should be an integer in the node ID list corresponding with the finish
%
% Outputs:
%     DIST is the shortest Euclidean distance
%       If FID was specified, DIST will be a 1x1 double representing the shortest
%         Euclidean distance between SID and FID along the map segments. DIST will have
%         a value of INF if there are no segments connecting SID and FID.
%       If FID was not specified, DIST will be a 1xN vector representing the shortest
%         Euclidean distance between SID and all other nodes on the map. DIST will have
%         a value of INF for any nodes that cannot be reached along segments of the map.
%     PATH is a list of nodes containing the shortest route
%       If FID was specified, PATH will be a 1xP vector of node IDs from SID to FID.
%         NAN will be returned if there are no segments connecting SID to FID.
%       If FID was not specified, PATH will be a 1xN cell of vectors representing the
%         shortest route from SID to all other nodes on the map. PATH will have a value
%         of NAN for any nodes that cannot be reached along the segments of the map.
%
% Example:
%     dijkstra; % calculates shortest path and distance between two nodes
%               % on a map of randomly generated nodes and segments
%
% Example:
%     nodes = [(1:10); 100*rand(2,10)]';
%     segments = [(1:17); floor(1:0.5:9); ceil(2:0.5:10)]';
%     figure; plot(nodes(:,2), nodes(:,3),'k.');
%     hold on;
%     for s = 1:17
%         if (s <= 10) text(nodes(s,2),nodes(s,3),[' ' num2str(s)]); end
%         plot(nodes(segments(s,2:3)',2),nodes(segments(s,2:3)',3),'k');
%     end
%     [d, p] = dijkstra(nodes, segments, 1, 10)
%     for n = 2:length(p)
%         plot(nodes(p(n-1:n),2),nodes(p(n-1:n),3),'r-.','linewidth',2);
%     end
%     hold off;
%
% Author: Joseph Kirk
% Email: jdkirk630 at gmail dot com
% Release: 1.3
% Release Date: 5/18/07
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Dijk Coordinates Presenting Connecting coordinate 网络 算法 程序 起点

dijkstra.rar
下载链接: https://bbs.pinggu.org/a-1199510.html

4.34 KB

需要: 5 个论坛币  [购买]

求网络最短路径dijkstra算法的三个不同程序

本附件包括:

  • Dijkstra2.m
  • dijkstra3.m
  • dijkstra.m

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
日新少年 + 1 + 1 + 1 精彩帖子

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

本帖被以下文库推荐

沙发
jcx350(未真实交易用户) 发表于 2013-12-10 17:14:55
谢谢

藤椅
日新少年(真实交易用户) 学生认证  发表于 2015-5-31 09:03:45
谢谢楼主分享呢

板凳
liangyu24585318(未真实交易用户) 发表于 2017-2-3 14:13:10
很好的软件

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-5 20:12