Function Repository Resource:

GeneralizedGridGraph

Source Notebook

Generates a generalized version of GridGraph

Contributed by: Max Piskunov

ResourceFunction["GeneralizedGridGraph"][{spec1,spec2,,speck}]

gives a k-dimensional generalized grid graph according to the specifications specj .

Details and Options

The specj can take any of the following forms:
mm vertices in the jth dimension
m “Circular” m vertices in the jth dimension connected cyclically
m “Directed”m vertices connected by directed edges in the jth dimension
m {“Circular”, “Directed”}m vertices in the jth dimension cyclically connected by directed edges
GeneralizedGridGraph takes the same options as Graph, with the following additional option:
“VertexNamingFunction”Automaticfunction to use for naming the vertices

Examples

Basic Examples (2) 

Generate an 8×8 grid graph with directed edges:

In[1]:=
LayeredGraphPlot[
 ResourceFunction[
  "GeneralizedGridGraph"][{8 -> "Directed", 8 -> "Directed"}], AspectRatio -> 1]
Out[1]=

Generate an 5×5×5 grid graph with directed edges:

In[2]:=
Graph3D[ResourceFunction[
  "GeneralizedGridGraph"][{5 -> "Directed", 5 -> "Directed", 5 -> "Directed"}]]
Out[2]=

Scope (3) 

Generate an ordinary grid graph:

In[3]:=
ResourceFunction["GeneralizedGridGraph"][{8, 10}]
Out[3]=

Generate a grid graph that is circular in the first dimension, and has directed edges in the second:

In[4]:=
ResourceFunction[
 "GeneralizedGridGraph"][{8 -> "Circular", 10 -> "Directed"}]
Out[4]=

Generate a grid graph that has directed edges and is circular in the first dimension:

In[5]:=
ResourceFunction[
 "GeneralizedGridGraph"][{8 -> {"Circular", "Directed"}, 10}]
Out[5]=

Options (4) 

EdgeStyle (1) 

Give an EdgeStyle:

In[6]:=
ResourceFunction[
  "GeneralizedGridGraph"][{10 -> "Directed", 10 -> "Directed"}, EdgeStyle -> {Red, Blue}] // LayeredGraphPlot
Out[6]=
In[7]:=
Graph3D[ResourceFunction[
  "GeneralizedGridGraph"][{3 -> "Directed", 3 -> "Directed", 3 -> "Directed"}, EdgeStyle -> {Gray, Blue, Red}]]
Out[7]=

VertexNamingFunction (3) 

Label vertices with their coordinates:

In[8]:=
ResourceFunction["GeneralizedGridGraph"][{3, 4}, "VertexNamingFunction" -> "Coordinates", VertexLabels -> Automatic]
Out[8]=

Labeling by coordinates works with arbitrary grids:

In[9]:=
ResourceFunction[
 "GeneralizedGridGraph"][{3 -> "Circular", 4 -> "Directed"}, "VertexNamingFunction" -> "Coordinates", VertexLabels -> Automatic]
Out[9]=

Labeling by coordinates works in any dimension:

In[10]:=
ResourceFunction["GeneralizedGridGraph"][{3, 4, 2}, "VertexNamingFunction" -> "Coordinates", VertexLabels -> Automatic]
Out[10]=

Properties and Relations (1) 

For plain integer specifications, GeneralizedGridGraph is the same as GridGraph:

In[11]:=
ResourceFunction["GeneralizedGridGraph"][{10, 10}]
Out[11]=
In[12]:=
GridGraph[{10, 10}]
Out[12]=

Version History

  • 2.0.0 – 16 March 2020
  • 1.0.0 – 09 March 2020

License Information