MathGroup Archive 2005

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

Search the Archive

graphs

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60946] graphs
  • From: leigh pascoe <leigh at cephb.fr>
  • Date: Wed, 5 Oct 2005 02:27:47 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Dear Mathgroup,

I am using Combinatorica to study a board game represented by a graph. 
The nxn graph can be created using

<<DiscreteMath`Combinatorica`
n=4;
g=GridGraph[n,n];
ShowGraph[g,VertexNumber\[Rule]True]

The vertices of the graph are numbered from the bottom left in rows, 
hence to refer to the matrix (row,column) location of a vertex we define 
a linking function.

cellindex[i_,j_]:=n*(n-i)+j;

Now to complete the graph we draw edges from cell(i,j) to cell(i-1,j+1), 
where these vertices exist. Here is an example for the 4x4 case

ShowGraph[
  g1=AddEdges[
      g,{{cellindex[2,1],cellindex[1,2]},{cellindex[2,2],
          cellindex[1,3]},{cellindex[2,3],cellindex[1,4]},{cellindex[3,1],
          cellindex[2,2]},{cellindex[3,2],cellindex[2,3]},{cellindex[3,3],
          cellindex[2,4]},{cellindex[4,1],cellindex[3,2]},{cellindex[4,2],
          cellindex[3,3]},{cellindex[4,3],cellindex[3,4]}}],
  VertexNumber\[Rule]True]

This works ok, but I now have several problems: I would like to write 
the above statement as an implied loop for a general nxn gridgraph. I 
can't seem to get the correct syntax for this. Can anyone help me?

Then I would like to define some functions on the graph, referring to 
the vertices by there grid position. However when I add or delete a 
vertex, the numbering on the graph changes. I would like to be able 
mutate the graph, but still be able to address vertices by the original 
labels, as defined by the cellindex[i,j] function (or any other for that 
matter. Any suggestions?

A third problem (bug?) is that in the ShowGraph command the vertex label 
on the left loses the left most digit(s) when displayed, as shown above. 
I just note that here in case someone at Wolfram wants to fix it.

The documentation for this package is also rather (very) limited. I 
bought the book on the package, which gives some more details, but many 
functions still remain undocumented. Does anyone know a better source?

Thanks for your replies.

Leigh


  • Prev by Date: Re: Partition(divid string to substring
  • Next by Date: Re: axes for Plot3D
  • Previous by thread: Re: Format.m , FortranAssign : weird identifiers for temporary variables
  • Next by thread: Re: graphs