⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdijkstra.mht

📁 寻找最短路径的程序,希望对大家有用,谢谢!主要是为了完成注册
💻 MHT
字号:
From: <由 Microsoft Internet Explorer 5 保存>
Subject: 
Date: Tue, 31 Mar 2009 11:07:06 +0800
MIME-Version: 1.0
Content-Type: text/html;
	charset="gb2312"
Content-Transfer-Encoding: 7bit
Content-Location: http://www.mathworks.com/matlabcentral/fx_files/23462/2/mdijkstra.m
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.3354" name=GENERATOR></HEAD>
<BODY><PRE>function [costs] = mdijkstra(A,C)
%
%A=square matrix (either adjecancy or cost)
%
%if C=1 then A=adjecancy matrix
%    where, element(i,j)=1 when vertex v is directly connected with j
%    else (i,j)=0
%
%if C=2 then A=cost matrix 
%    where, element (i,j) represents positive integer representing cost
%    between vertex i and j
%
% Output: [costs]: calculated cost matrix
% Developed by: Bharat Patel
% Release date: 03/28/2009

n = length(A);
costs=single(A);
costs(costs==0)=Inf;
for k = 1:n
    disp(sprintf('%d/13-%d/%d',C,k,n));
    w_col=single(costs(:,k));
    if C==1
        mx=max(w_col(find(w_col~=Inf)));
        pmx=0;
        while(mx~=pmx)
            cols=find(w_col==mx);
            tmp=min(costs(:,cols),[],2);
            tmp=tmp+mx;
            tmp1=[w_col tmp];
            w_col=min(tmp1,[],2);
            pmx=mx;
            mx=max(w_col(find(w_col~=Inf)));
        end
        costs(:,k)=w_col;
    elseif C==2
        m1=(w_col(find(w_col)));
        m=sort(unique(m1),'ascend');
        for j=1:length(m)
            mx=m(j);
            cols=find(w_col==mx);
            tmp=min(costs(:,cols),[],2);
            tmp=tmp+mx;
            tmp1=[w_col tmp];
            w_col=min(tmp1,[],2);
        end
        costs(:,k)=w_col;
        costs(k,:)=w_col';
    end
end
for k=1:n
    costs(k,k)=0;
end



</PRE></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -