使用Matlab的graphshortestpath 函数,快速求得最短路径,详情请参照Matlab帮助文档。
graphshortestpath solves the shortest path problem in graph.
[DIST,PATH,PRED] = graphshortestpath(G,S) determines the single source
shortest paths from node S to all other nodes in the graph G. Weights of
the edges are all nonzero entries in the n-by-n adjacency matrix
represented by the sparse matrix G. DIST are the n distances from source
to every node (using Inf for non-reachable nodes and zero for the source
node). The PATH contains the winning paths to every node, and PRED
contains the predecessor nodes of the winning paths.
[DIST,PATH,PRED] = graphshortestpath(G,S,D) determines the single
source-single destination shortest path from node S to node D.
graphshortestpath(...,'METHOD',METHOD) selects the algorithm to use,
options are:
'BFS' - Breadth First Search, assumes all the weights are
equal, edges are nonzero entries in the sparse matrix