Sunday 6 January 2013

Generating n-dimensional graphs

The python networkx package has great support for a whole range of graphs that appear in common situations. One thing that pops up occasionally is the need for slightly more sophisticated lattices (grid graphs) than what are available.

For example, when you're modelling a discrete approximation to position and heading in two dimensions - position should not wrap, but the heading should.

So this is my code to generate an n-dimensional grid graph, which allows each dimension to be periodic independently.