next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Graphs :: distanceMatrix

distanceMatrix -- Computes the distance matrix of a digraph

Synopsis

Description

The distance matrix is the matrix where entry M_(i,j) corresponds to the distance between vertex indexed i and vertex indexed j in the specified graph. If the distance between two vertexSet is infinite (i.e. the vertexSet are not connected) the matrix lists the distance as -1.

i1 : G = graph({{1,2},{2,3},{3,4}},EntryMode=>"edges");
i2 : d = distanceMatrix G

o2 = | 0 1 2 3 |
     | 1 0 1 2 |
     | 2 1 0 1 |
     | 3 2 1 0 |

              4        4
o2 : Matrix ZZ  <--- ZZ
i3 : G = digraph({1,2,3,4},{{2,3},{3,4}},EntryMode=>"edges");
i4 : d = distanceMatrix G

o4 = | 0  -1 -1 -1 |
     | -1 0  1  2  |
     | -1 -1 0  1  |
     | -1 -1 -1 0  |

              4        4
o4 : Matrix ZZ  <--- ZZ

See also

Ways to use distanceMatrix :

For the programmer

The object distanceMatrix is a method function.