# Odd behavior of GridGraph and DirectedEdges

For some reason the option DirectedEdges->True, albeit working internally with grid graph, does not appear in the visualisation for 1D and 2D graphs. It also changes the drawing scheme for 3D grids.

1D Grid-Graphs

Using

g1 = GridGraph[{2}, VertexLabels -> "Name", ImagePadding -> 20, DirectedEdges -> True]


prints:

which shows no directed edges, even though the incidence matrix is modified correctly:

$$\text{IncidenceMatrix[g1]} = \left( \begin{array}{c} -1 \\ 1 \end{array} \right)$$

Conversely, issuing the command

GridGraph[{1,2}, VertexLabels -> "Name", ImagePadding -> 20, DirectedEdges -> True]


prints

ie, with the directed edges correctly drawn.

2D Grid-Graphs

For 2D graphs, small dimensions print as a directed edge whereas higher dimensions do not. For instance

g = GridGraph[{2, 2}, VertexLabels -> "Name", ImagePadding -> 20, DirectedEdges -> True]


produces:

For dimensions {4,2} the graph is:

where some very tiny arrows can in fact be observed. Conversely, for dimensions {2,4} it produces

It thence seems like a problem in adjusting the size of the arrows. But this seems unrelated to the 1D graph since there, no arrow can be seen in any dimension (unless drawn horizontally, in which case a 2D Grid-Graph is actually being called).

3D Grid-Graphs

Apparently, the arrows are drawn correctly for dimensions 3 and larger. However, the drawing scheme is affected, which is not the case in 2D graphs. For instance

 GridGraph[{4, 2, 2}, VertexLabels -> "Name", ImagePadding -> 20]


produces

whereas adding DirectedEdges->True yields

In summary: odd stuff. Any thoughts? Thank you in advance for the attention.

-
It seems a problem with the arrows scaling. Try GridGraph[{2}, VertexLabels -> "Name", ImagePadding -> 20, DirectedEdges -> True, EdgeShapeFunction -> GraphElementData["FilledArrow", "ArrowSize" -> 2]] i.stack.imgur.com/0uEyD.png  – Dr. belisarius Aug 23 '12 at 2:01

There is something wrong with the behavior of EdgeShapeFunction in GridGraph.

AbsoluteOptions[g, EdgeShapeFunction] returns $Failed for all of the examples you give. Take a look at the this blow-up of g1. There is indeed a tiny arrowhead present. g1 = GridGraph[{2}, VertexLabels -> "Name", ImageSize -> 300, ImagePadding -> 20, DirectedEdges -> True]  Verde's suggestion to use GraphElementData["FilledArrow", "ArrowSize" -> 2] handles the issue of arrowhead size. However it introduces a new problem (see magnified pic of Verde's proposed solution). The tip of the arrowhead is now incorrectly positioned at the center of the vertex. I suggest you call attention of WRI to this as a possible bug. - David: I wasn't suggesting to use that! The idea was showing that the arrow is there ... – Dr. belisarius Aug 23 '12 at 3:41 And ... It isn't AbsoluteOptions but PropertyValue what you need to get the option for EdgeShapeFunction – Dr. belisarius Aug 23 '12 at 3:45 Verde: Sorry if I was unable to understand the intent of your comment. Btw, why does AbsoluteOptions return $Failed? – DavidC Aug 23 '12 at 10:45
David, I think WRI is changing the way to access internal structures, but it is only partially done. AbsoluteOptions, PropertyValue, CurrentValue ... I think future versions will converge these – Dr. belisarius Aug 23 '12 at 11:43
@DavidCarraher Thanks for the answer. I'll report it as a possible bug. I am not sure this is related, but GridGraph draws the graph differently from other graphs. – Gabriel Landi Aug 23 '12 at 11:52

As Verde said, it seems an arrow scaling problem:

origgraph = GridGraph[{2},
VertexLabels -> "Name", DirectedEdges -> True,

With[
ToBoxes[origgraph] /.
{arrowstyle, ArrowBox[pts]} //
ToExpression]


About the overlay problem about GraphElementData["FilledArrow", "ArrowSize" -> 2] described in David's answer, it seems like because when option EdgeShapeFunction -> GraphElementData["FilledArrow", "ArrowSize" -> 2] is specified, explicit coordinates are (incorrectly?) used in ArrowBox instead of DynamicLocation. It can be worked around as following:

origgraph = GridGraph[{2},
VertexLabels -> "Name", DirectedEdges -> True,
ImagePadding -> 20, ImageSize -> 100];

arrowgraph = GridGraph[{2},
VertexLabels -> "Name",
DirectedEdges -> True,
EdgeShapeFunction ->
GraphElementData["FilledArrow", "ArrowSize" -> 2],
ImagePadding -> 20, ImageSize -> 100];

finalgraph = With[
{arrowstyle =
Cases[arrowgraph // ToBoxes,
`