From: Daniel Lichtblau on
Jon Harrop wrote:
> Given a graph represented as edges between vertices, such as the following:
>
> g = {"1" -> "2", "1" -> "10", "1" -> "11", "2" -> "3", "2" -> "18",
> "3" -> "4", "3" -> "12", "4" -> "5", "4" -> "19", "5" -> "6",
> "5" -> "13", "6" -> "7", "6" -> "20", "7" -> "8", "7" -> "14",
> "8" -> "9", "8" -> "16", "9" -> "10", "9" -> "15", "10" -> "17",
> "11" -> "15", "11" -> "12", "12" -> "13", "13" -> "14",
> "14" -> "15", "16" -> "20", "16" -> "17", "17" -> "18",
> "18" -> "19", "19" -> "20"}
>
> You can use GraphDistanceMatrix to compute the all-pairs shortest paths as a
> matrix. However, without knowledge of the mapping from vertex names to
> indices in the resulting matrix, the output is useless. So how are you
> supposed to use this function?

Needs["GraphUtilities`"]

VertexList will retain the correspondence between your vertex names and
the vertex positions in the adjacency matrix.

In[145]:= ag = AdjacencyMatrix[g];
InputForm[vl = VertexList[g]]

Out[146]//InputForm=
{"1", "2", "10", "11", "3", "18", "4", "12", "5", "19", "6",
"13", "7", "20", "8", "14", "9", "16", "15", "17"}

Daniel Lichtblau
Wolfram Research

From: Jon Harrop on
"Daniel Lichtblau" <danl(a)wolfram.com> wrote in message
news:i3bd2v$pe0$1(a)smc.vnet.net...
> Jon Harrop wrote:
>> Given a graph represented as edges between vertices, such as the
>> following:
>>
>> g = {"1" -> "2", "1" -> "10", "1" -> "11", "2" -> "3", "2" -> "18",
>> "3" -> "4", "3" -> "12", "4" -> "5", "4" -> "19", "5" -> "6",
>> "5" -> "13", "6" -> "7", "6" -> "20", "7" -> "8", "7" -> "14",
>> "8" -> "9", "8" -> "16", "9" -> "10", "9" -> "15", "10" -> "17",
>> "11" -> "15", "11" -> "12", "12" -> "13", "13" -> "14",
>> "14" -> "15", "16" -> "20", "16" -> "17", "17" -> "18",
>> "18" -> "19", "19" -> "20"}
>>
>> You can use GraphDistanceMatrix to compute the all-pairs shortest paths
>> as a
>> matrix. However, without knowledge of the mapping from vertex names to
>> indices in the resulting matrix, the output is useless. So how are you
>> supposed to use this function?
>
> Needs["GraphUtilities`"]
>
> VertexList will retain the correspondence between your vertex names and
> the vertex positions in the adjacency matrix.
>
> In[145]:= ag = AdjacencyMatrix[g];
> InputForm[vl = VertexList[g]]
>
> Out[146]//InputForm=
> {"1", "2", "10", "11", "3", "18", "4", "12", "5", "19", "6",
> "13", "7", "20", "8", "14", "9", "16", "15", "17"}

Ah, thank you!

Cheers,
Jon.