Is it possible for Mathematica to layout a graph so that the connections lie on a grid? Furthermore, for graphs with multiple edges per vertex, is it possible to specify the location on the vertex for each connection? The context of this question is to use Mathematica's graph functionality to represent / visualize networks of circuit components. Each component has some number of input and output ports and I would like to be able to generate a network layout based on a connectivity map (netlist). I've been using GraphPlot and LayeredGraphPlot and have looked through quite a few different options but none that quite address these issues.

===== EDIT (by @VitaliyKaurov): ====

Reading @Szabolcs and @gsarma comments I am posting the image they to refer and which is approximately what is needed.

Can the edges turn 90 degrees, or are they always straight (i.e. the graph is very special)? @R.M I think he means that he already has a graph, and needs to lay it out so that all edges run along a square grid.
–
SzabolcsMay 11 '12 at 8:12

3

@R.M But it might not be a full grid. Maybe it's a graph with only 20 vertices, and it's being laid out on a 10 by 10 grid. Maybe the edge lengths can be any multiples of the cell size of the grid. "Fitting" the graph onto the grid (i.e. calculating the correct VertexCoordinates) becomes not so trivial in this case. This is how I understand the question, but I agree it needs clarification.
–
SzabolcsMay 11 '12 at 8:29

1

@Szabolcs Yes, that is what I am looking for.
–
systematicMay 11 '12 at 8:47

2 Answers
2

The main problem here I think is laying out edges along orthogonal lines. This can be addressed with splines. First define function that triples every element in the list to make a spline to pass sharply through the points.

mlls[l_] := Flatten[Transpose[Table[l, {i, 3}]], 1];

In the function below I'll define a special EdgeRenderingFunction, a trick learned from @Yu-SungChang . Using LayeredGraphPlot:

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.