# More efficient way to generate lattice graph with edges between visible vertices?

Given a nXn lattice, I need to generate the graph such that there is an edge between two vertices iff they are directly "visible" to each other, i.e., there is no vertex between them.

I'm using

latticeSize = 3;
vertices = Range[latticeSize^2];
coords = Transpose[{Ceiling[vertices/latticeSize],
Mod[vertices, latticeSize, 1]}];
coordsPairs = Subsets[coords, {2}];
graph = UndirectedEdge @@@
Replace[Pick[coordsPairs,
Map[GCD[#[[2, 1]] - #[[1, 1]], #[[2, 2]] - #[[1, 2]]] == 1 &,
Graph[graph, VertexCoordinates -> Thread[vertices -> coords]]


I've poked at built-in graphs to try to find a predefined graph of this sort (oh, how I'd pay extra to have a graph search engine in MMA).

Might someone know of such a built-in, or if not, a more efficient mechanism to generate them?

• "efficient" as in "fast"? – Dr. belisarius Sep 15 '15 at 2:18
• @belisarius well, it's ok speed wise - I could shave time vectorizing the gcd, but really memory becomes the issue before that matters - the subsetting gets big fast. Kind of hoping someone chimes in with "...duh, that's just the built-in BigSquareGraphWithEdgesBetweenNonOccludedVertices..." (probably a version 11 addition ;-} ) – ciao Sep 15 '15 at 2:23
• Oh, Ok. Thanks. That was my guess :) – Dr. belisarius Sep 15 '15 at 2:30
• Number of edges – Dr. belisarius Sep 15 '15 at 2:54
• I saw that. But OEIS links to a paper that seems to contain more info. Too late here to read it – Dr. belisarius Sep 15 '15 at 3:52