Mathematica 9 is now available
Student Support Forum
Student Support Forum: 'how construct a graph' topicStudent Support Forum > General > "how construct a graph"

< Previous CommentHelp | Reply To Comment | Reply To Topic
Author Comment/Response
Daniel Z-S
09/30/10 11:40am

In Response To 'Re: Re: how construct a graph'
"i believe Norm[points[[i]] - #] calculate the distance between the two vertices, if {{1, 1}, {1, 2}, {1, 3}, {2, 1}, {2, 2}, {2, 3}, {3, 1}, {3, 2}, {3, 3}} are the same as the coordinate of every vertex. In this case the vertex coordinate in Graph g = GridGraph[3,3]are same as the list points."

They are not just the coordinates of the vertices, they ARE the vertices. But yes, the vertices are the same as those of the grid graph. Was that not what you intended? I understood you as though you wanted something similar to a grid graph, only with another edge set,

"Therefore i believe that

pointsSet =
Map[{points[[i]], #} &, connectingPoints[[i]]], {i, Length@points}], 1]

calculate only the vertices coordinate set not the edges set."

No, it does generate the edge set, but the edges are just pairs of vertices, so you are going to see the vertices (which are identical to their coordinates the way we did it) when you look at the edge list.

However, this whole thing does not work as I inteded, as I found out with some more testing (which ofc I should have done right away.) The problem is that GraphPlot (and so presumably the entire GraphUtilities package) didn't like the way I used coordinates as vertices, in an undirected graph. Probably something with the nesting of lists. This is easily fixable: Just change the last function to


edges = Flatten[Table[
Map[points[[i]] -> # &, connectingPoints[[i]]], {i, Length@points}],

This function generated the edge set. The difference is that instead of generating edges looking like {v1, v2} they now look like v1->v2, and are directed. GraphPlot can plot this directly, but it contains directed multiple edges, and self-loops, all artifacts of the generating process we did. But we can just do



and voilá, we Combinatorica made it simple for us. Now this DOES work, at least for me. I get perfectly looking "extended" grid graphs, just like I intended. They may of course not be exactly what you intended, but that is just a thing of specifying the correct SelectFunction (that I talked about in my first reply.)

URL: ,

Subject (listing for 'how construct a graph')
Author Date Posted
how construct a graph Zhiyu Fan 09/20/10 05:41am
Re: how construct a graph Daniel Z-S 09/23/10 3:20pm
Re: Re: how construct a graph Zhiyu Fan 09/24/10 11:12am
Re: Re: Re: how construct a graph Daniel Z-S 09/30/10 11:40am
< Previous CommentHelp | Reply To Comment | Reply To Topic