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

📄 routing.m

📁 this is use the matlab...routing protocol shortest path algorithm
💻 M
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -