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: [mg111605] Re: Relationship between vertices and indices with GraphDistanceMatrix
  • From: "Jon Harrop" <usenet at ffconsultancy.com>
  • Date: Sat, 7 Aug 2010 01:31:36 -0400 (EDT)
  • References: <i3bd2v$pe0$1@smc.vnet.net>

"Daniel Lichtblau" <danl at wolfram.com> wrote in message 
news:i3bd2v$pe0$1 at 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.



  • Prev by Date: > classroom combinatorics
  • Next by Date: Re: classroom combinatorics
  • Previous by thread: Re: Relationship between vertices and indices with GraphDistanceMatrix
  • Next by thread: AbsoluteTime and Daylight Saving Time