routing.m

来自「this is use the matlab...routing protoco」· M 代码 · 共 43 行

M
43
字号
clc
clear
n=input('Total node(<26)= ');
if n > 26
    error('not <26;;')
end
alphabets= char(65:1:65+n);
adj=zeros(n,n);
for p=1:n
    for q=1:n
        adj(p,q)=input(['Enter Weight between [',alphabets(p),']','[',alphabets(q),'] = ']);
    end
end
for p=1:n
    a(p).status=0;
end
temp=[];
acc=[];
s=input('Please enter the source node = ');
t=input('Please enter the destination node = ');
a(s).status=1; 
path=s;
for k=1:inf
for h=1:n
 if a(h).status==0   
     temp=[temp adj(s,h)];
 else
     temp=[temp inf];
 end
end
[aa,bb]=min(temp);
acc=[acc aa];
temp=[];
s=bb;
a(s).status=1;
path=[path s];
if s==t
    break
end
end
helpdlg(['Path : ' alphabets(path) '  Total Cost/Weight : '...
        num2str(sum(acc))],'Greedy Dijkstra Algorithm')

⌨️ 快捷键说明

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