求用matlab解最短路问题的程序
来源:百度知道 编辑:UC知道 时间:2024/05/17 22:26:36
衷心期盼有好心人帮忙,谢谢了!
% 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