GraphUtilities`
GraphUtilities`

GraphDistance

As of Version 10, all the functionality of the GraphUtilities package is built into the Wolfram System. »

GraphDistance[g,i,j]

gives the distance from vertex i to vertex j in the graph g.

更多信息和选项

  • GraphDistance functionality is now available in the built-in Wolfram Language function GraphDistance.
  • To use GraphDistance, you first need to load the Graph Utilities Package using Needs["GraphUtilities`"].
  • GraphDistance returns the graph distance from one vertex to another. Infinity is returned if no path exists from i to j. By default every edge is assumed to have an edge weight of 1.
  • The following option can be used:
  • WeightedFalsespecifies whether edge weight is to be used in calculating distance

范例

打开所有单元关闭所有单元

基本范例  (2)

This defines a simple directed graph:

This calculates the distance from vertex 1 to vertex 5:

This function has been superseded by GraphDistance in the Wolfram System:

Scope  (1)

This defines a simple directed graph:

This calculates the distance from vertex 1 to vertex 5:

There is no path from vertex 4 to vertex 1:

This defines a simple directed graph with edge weights:

This shows that the distance from vertex 1 to 3 is 2 if unit edge weights are assumed:

But the distance becomes 0 if edge weights are taken into account:

Applications  (1)

This generates a random directed graph with n nodes and degree d:

Average distance between vertices 1 and 100, of 200 random directed graphs of 100 vertices and degree 2:

The average distance decreases with an increase in the degree:

Possible Issues  (1)

This defines a small directed graph:

This shows that the distance between vertices 1 and 3 is 2, assuming a unit edge weight:

This shows that when edge weights are taken into account, the distance between vertices 1 and 3 is 0:

This shows the shortest path when edge weights are taken into account:

This shows the shortest path when edge weights are ignored:

Wolfram Research (2007),GraphDistance,Wolfram 语言函数,https://reference.wolfram.com/language/GraphUtilities/ref/GraphDistance.html.

文本

Wolfram Research (2007),GraphDistance,Wolfram 语言函数,https://reference.wolfram.com/language/GraphUtilities/ref/GraphDistance.html.

CMS

Wolfram 语言. 2007. "GraphDistance." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/GraphUtilities/ref/GraphDistance.html.

APA

Wolfram 语言. (2007). GraphDistance. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/GraphUtilities/ref/GraphDistance.html 年

BibTeX

@misc{reference.wolfram_2024_graphdistance, author="Wolfram Research", title="{GraphDistance}", year="2007", howpublished="\url{https://reference.wolfram.com/language/GraphUtilities/ref/GraphDistance.html}", note=[Accessed: 18-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_graphdistance, organization={Wolfram Research}, title={GraphDistance}, year={2007}, url={https://reference.wolfram.com/language/GraphUtilities/ref/GraphDistance.html}, note=[Accessed: 18-November-2024 ]}