matlab 單元最短路 Dijkstra演算法 有向圖 無向圖

來源:互聯網
上載者:User

標籤:最短路   mat   text   gety   bsp   a演算法   owa   src   size   

 

W = [2 8 1 1 6 5 1 2 3 6 4 9 3 7 9];S = [0 0 0 1 1 3 3 3 5 5 6 4 6 2 2];S=S+1;T = [1 3 2 4 3 4 5 6 4 7 5 7 7 3 6];T=T+1;IDS={‘u0‘,‘u1‘,‘u2‘,‘u3‘,‘u4‘,‘u5‘,‘u6‘,‘u7‘};DG = sparse(S,T,W,8,8)%求疏鬆陣列UG =tril(DG+DG‘)%取矩陣和轉置矩陣和的下三角矩陣。bg=biograph(DG,IDS,‘ShowArrows‘,‘off‘,‘ShowWeights‘,‘on‘);%構建biograph對象,設定參數set(bg.nodes,‘shape‘,‘circle‘,‘color‘,[1,1,0],‘linecolor‘,[0,0,1]);set(bg.nodes,‘textColor‘,[0,0,0],‘lineWidth‘,2,‘fontsize‘,9);set(bg,‘EdgeType‘,‘straight‘);%設定連線為直線 get(bg.nodes,‘position‘);%擷取節點位置dolayout(bg);bg.nodes(1).position=[9,100];bg.nodes(2).position=[101,182];bg.nodes(3).position=[101,10];bg.nodes(4).position=[101,100];bg.nodes(5).position=[214,182];bg.nodes(6).position=[214,100];bg.nodes(7).position=[214,10];bg.nodes(8).position=[303,100];dolayout(bg,‘pathsonly‘,true);t = view(bg)[dist,path,pred] = graphshortestpath(UG,1,8,‘directed‘,false)%Dijkstra求最短路

 

matlab 單元最短路 Dijkstra演算法 有向圖 無向圖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.