GraphPath
GraphPath[g,start,end]
finds a shortest path between vertices start and end in graph g.
更多信息和选项
- GraphPath functionality is now available in the built-in Wolfram Language function FindShortestPath.
- To use GraphPath, you first need to load the Graph Utilities Package using Needs["GraphUtilities`"].
- The following options can be used:
-
Method Automatic method to use to find the shortest path Weighted True specify whether edge weight is to be used in calculating distance
范例
打开所有单元关闭所有单元基本范例 (2)
This defines a small directed graph:
This finds the shortest path from vertex 1 to vertex 3:
This finds the shortest path from vertex 1 to vertex 3, ignoring the edge weights:
GraphPath has been superseded by FindShortestPath:
Options (1)
Method (1)
Because of the negative edge weight, the Dijkstra algorithm cannot be applied:
The Bellman–Ford algorithm works:
This defines a small graph with a negative cycle:
The Dijkstra algorithm does not work for negative edge weights:
The Bellman–Ford algorithm detects a negative weight cycle:
The default algorithm for graphs with negative edge weights is Bellman–Ford:
Properties & Relations (1)
Possible Issues (1)
文本
Wolfram Research (2007),GraphPath,Wolfram 语言函数,https://reference.wolfram.com/language/GraphUtilities/ref/GraphPath.html.
CMS
Wolfram 语言. 2007. "GraphPath." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/GraphUtilities/ref/GraphPath.html.
APA
Wolfram 语言. (2007). GraphPath. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/GraphUtilities/ref/GraphPath.html 年