| 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 =
Flatten[Table[
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
(HERE IS THE FIX FOR PREVIOUS CODE:)
edges = Flatten[Table[
Map[points[[i]] -> # &, connectingPoints[[i]]], {i, Length@points}],
1]
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 THIS TIDYS UP THE GRAPH)
GraphPlot@MakeSimple@ToCombinatoricaGraph@edges
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: , |
|