图论--Matlab实现最短路径算法

本文介绍了如何使用Matlab的graphshortestpath函数求解最短路径问题,包括单源最短路径和单源单目标最短路径。详细阐述了函数的参数选项,如算法选择、权重设置和图的定向。并提供了示例代码展示如何创建图、找到最短路径并标记路径上的节点和边。
摘要由CSDN通过智能技术生成

       使用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

               

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值