MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Relationship between vertices and indices with GraphDistanceMatrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111522] Re: Relationship between vertices and indices with GraphDistanceMatrix
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Wed, 4 Aug 2010 05:48:46 -0400 (EDT)

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


  • Prev by Date: Re: Disable " symbol
  • Next by Date: AbsoluteTime and Daylight Saving Time
  • Previous by thread: Re: Can't get Mathematica to evaluate correctly a difficult expression
  • Next by thread: Re: Relationship between vertices and indices with GraphDistanceMatrix