|
SOLUTIONS
|
GRAPH UTILITIES 程序包 符号
GraphDistance
![]()
gives the distance from vertex i to vertex j in the graph g.
更多信息更多信息
- To use
, you first need to load the Graph Utilities Package using Needs["GraphUtilities`"].
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:
-
Weighted False specifies whether edge weight is to be used in calculating distance
范例范例打开所有单元关闭所有单元
基本范例 (1)基本范例 (1)
| In[1]:= |
This defines a simple directed graph:
| In[2]:= |
| In[3]:= |
| Out[3]= | ![]() |
This calculates the distance from vertex 1 to vertex 5:
| In[4]:= |
| Out[4]= |
There is no path from vertex 4 to vertex 1:
| In[5]:= |
| Out[5]= |
This defines a simple directed graph with edge weights:
| In[6]:= |
| In[7]:= |
| Out[7]= | ![]() |
This shows that the distance from vertex 1 to 3 is 2 if unit edge weights are assumed:
| In[8]:= |
| Out[8]= |
But the distance becomes 0 if edge weights are taken into account:
| In[9]:= |
| Out[9]= |
Mathematica 9 is now available!
New to Mathematica?
Find your learning path »
Have a question?
Ask support »



