當前位置:編程學習大全網 - 編程軟體 - matlab 中有這樣壹個函數:[dist, path, pred] = graphshortestpath(G, S, T),問壹下pred具體是什麽意思

matlab 中有這樣壹個函數:[dist, path, pred] = graphshortestpath(G, S, T),問壹下pred具體是什麽意思

它表示從S到每個節點的最短路徑中,目標節點的先驅,即目標節點的前面壹個節點。

例如下面的代碼。妳看每壹組返回值中,path向量的倒數第二個數,跟pred中相應節點的數字是不是相同。即依次抽取path的倒數第二個值,組成了pred數組。

>> W = [.41 .99 .51 .32 .15 .45 .38 .32 .36 .29 .21];

>> DG = sparse([6 1 2 2 3 4 4 5 5 6 1],[2 6 3 5 4 1 6 3 4 3 5],W);

>> [dist,path,pred] = graphshortestpath(DG,1,1)

dist =

0

path =

1

pred =

0 6 5 5 1 4

>> [dist,path,pred] = graphshortestpath(DG,1,2)

dist =

1.3600

path =

1 5 4 6 2

pred =

0 6 5 5 1 4

>> [dist,path,pred] = graphshortestpath(DG,1,3)

dist =

0.5300

path =

1 5 3

pred =

0 6 5 5 1 4

>> [dist,path,pred] = graphshortestpath(DG,1,4)

dist =

0.5700

path =

1 5 4

pred =

0 6 5 5 1 4

>> [dist,path,pred] = graphshortestpath(DG,1,5)

dist =

0.2100

path =

1 5

pred =

0 6 5 5 1 4

>> [dist,path,pred] = graphshortestpath(DG,1,6)

dist =

0.9500

path =

1 5 4 6

pred =

0 6 5 5 1 4

  • 上一篇:漫畫視頻怎麽制作
  • 下一篇:如何在視頻中P壹個球飛出去
  • copyright 2024編程學習大全網