求用matlab解最短路问题的程序要用Dijkstra算法找出任意两点间的最短路径.希望用MATLAB或LINGO编程求解.求程序,

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/08 17:08:36
求用matlab解最短路问题的程序要用Dijkstra算法找出任意两点间的最短路径.希望用MATLAB或LINGO编程求解.求程序,
xVMo5+Ί&)R!iQ Q؛q3k[''" 4*!^(B QڪMN^d@\Y>~u1Cl {÷{;䷟N~9}0dQxhӏ;~7ѯQc?=ɧ? ߾ek[ۯ9{rzkY{]wI9ٲX v ś.kV.ڠu00 C$' uZVTgI_SԔkdrtĕJ *(GYp@#ƨ}ǰMnlbO(faŤ\kԈ'͞2G YQq0' cQsAh8P5tj4ηᅦ^a5B_8hT:ԡ we L=̱s컬K$w[6zv e W𢦥õ7ѫDе+/-_YY%l0Iwo$P06!BH1DYTh\Ƌ>+ׄ*sI΢5A/ ;(!L3jӴx/pWܳ\$b `ޙ~٠ YY@U#.Ť[ہy@w7$B:"ux " (Tr1nAFOB XSKHT"Zڀ_ nBs2m倨Mӌ?mC;7wLHchFù`MY\5j-n+ L$.ǖXe9 AF@~>hަ,(CHV\y. S IM$-=d`tjC ݰAl%dF`|KNL eiqC;/' \ [u& =:jGG~c=IKIl.`>noB]0:4czGtmPjp4Gn;Vb@Æd2  !#_`lz'o6[4ڄ%&7Nze-1߰2

求用matlab解最短路问题的程序要用Dijkstra算法找出任意两点间的最短路径.希望用MATLAB或LINGO编程求解.求程序,
求用matlab解最短路问题的程序
要用Dijkstra算法找出任意两点间的最短路径.希望用MATLAB或LINGO编程求解.求程序,

求用matlab解最短路问题的程序要用Dijkstra算法找出任意两点间的最短路径.希望用MATLAB或LINGO编程求解.求程序,
% Dijkstra's Shortest Path
%
% final = dijkstra( A,x,y )
%
% Description:returns the shortest path from x to y given adjacency
% matrix A.Utilizes Dijkstra's shortest path algorithm.
%
% A = adjacency matrix of the graph (includes point x and y)
% x = intial node
% y = terminal node
% IN = set of nodes whose shortest path from x is known
% z,p = temporary nodes
% d = vector of lengths from initial point.i.e.d(p) = x to p
% s = vector of the previous node on a shortest path for any node
%
% Author:Josh Eads
% Date:1/23/2006
function final = dijkstra( A,x,y )
%modify A so that lengths of 0 are invalid (-1)
A(find(A == 0)) = NaN;
%initialize IN to include only x
IN = x;
%initialize s
s = zeros(1,length(A));
%initialize d & d(x) (distance to self)
d = zeros(1,length(A));
d(x) = 0;
%loop through all the nodes in A
for z = 1:length(A)
%don't calculate values already in IN
%if (find(IN == z))
if isWithin(IN,z)
%grab the distance from x to z from A (-1 denotes unreachable)
d(z) = A(x,z);
%set the previous node to x
s(z) = x;
end
end
%process nodes into IN
%while y isn't in set IN
%while (find(IN == y))
while isWithin(IN,y)
tempMin = [];
%add the node not in IN with the minimum distance into IN
for z = 1:length(A)
%if z isn't in IN
%if (find(IN == z))
if isWithin(IN,z)
tempMin = [tempMin,d(z)];
end
end
%find the minimum value from tempMin
p = min(tempMin);
%find the minimum distance nodes
search = find(d == p);
%cycle through all the minimum distance nodes until one not in IN is
%found
for i = 1:length(search)
search = find(d == p);
%store in p if the node isn't in IN
if( isWithin(IN,search(i)) )
p = search(i);
break;
end
end
%add node p into IN
IN = [IN,p];
%recompute d for all non-IN nodes,and adjust s
for z = 1:length(A)
%if z isn't in IN
%if (find(IN == z))
if isWithin(IN,z)
oldDistance = d(z);
%if the new path is shorter for z,update d(z)
d(z) = min(d(z),d(p) + A(p,z));
%if the new and old distances don't match,update s(z)
if (d(z) == oldDistance)
s(z) = p;
end
end
end
end
%write the shortest path to final
final = y;
z = y;
while (z == x) == 0
final = [final,s(z)];
z = s(z);
end
final=fliplr(final);
% isWithin Function
% source = matrix to search through
% search = item to search for
%
% returns - true if search is within source
function truth = isWithin(source,search)
truth = 0;
for i = 1:length(source)
if(source(i) == search)
truth = 1;
end
end

求用matlab解最短路问题的程序要用Dijkstra算法找出任意两点间的最短路径.希望用MATLAB或LINGO编程求解.求程序, Dijkstra最短路算法通用Matlab程序 Dijkstra最短路算法通用Matlab程序function [d,DD]=dijkstra(D,s)%Dijkstra最短路算法Matlab程序用于求从起始点s到其它各点的最短路%D为赋权邻接矩阵%d为s到其它各点最短路 图论中求解最短路的dijkstra法的MATLAB程序中最后的矩阵DD是什么意思?MATLAB程序:function [d,DD]=dijkstra(D,s)%Dijkstra最短路算法Matlab程序用于求从起始点s到其它各点的最短路%D为赋权邻接矩阵%d为s( matlab求最短路,运行dijkstra函数时出错function [d,DD]=dijkstra(D,s)%Dijkstra最短路算法Matlab程序用于求从起始点s到其它各点的最短路%D为赋权邻接矩阵%d为s到其它各点最短路径的长度; %DD记载了最短路 MATLAB求最短路 matlab运行dijkstra函数出错function [d,DD]=dijkstra(D,s)%Dijkstra最短路算法Matlab程序用于求从起始点s到其它各点的最短路%D为赋权邻接矩阵%d为s到其它各点最短路径的长度; %DD记载了最短路径生成树[m,n matlab求最短距离的程序 关于matlab中的一个Dijkstra算法应用算法如下:function[d,DD]=dijkstra(D,s)%Dijkstra最短路算法Matlab程序用于求从起始点s到其它各点的最短路%D为赋权邻接矩阵%d为s到其它各点最短路径的长度%DD记载了 matlab求最佳哈密顿圈遇到错误求最佳哈密顿圈遇到错误程序如下%用矩阵翻转方法来实现二边逐次修**过程,求最佳哈密尔顿圈(H圈)clcclearload('zd.mat');D=ZD;%floyd算法求得的每对地点之间最短路 急求应用matlab解决以下问题用matlab验证惯性质量与引力质量的相等,求实验过程和matlab验证程序 一般求最短路问题用什么软件运算? 用Matlab求(d^3(xe^x))/dx^3的程序怎么写啊! 用matlab求三个自变量函数最小值的M程序? 求用matlab产生m序列的程序 求用MATLAB编写的层次分析法程序 急求用matlab 6.0 求sinx是求sinx的,用matlab的程序。 求基于BP神经网络的英文大写字母的识别算法的MATLAB程序用matlab设计一个BP网络,要给出完整程序. 关于matlab求最小值最小值点的问题求大神附上matlab程序