# HG changeset patch
# User Nathann Cohen
# Date 1259507882 3600
# Node ID 785fec521c35cccbff80cf8c389f8ad677c8ac93
# Parent fee71ad457d0b6881f989cbe69b9bfe2eee0cd55
Toroidal Grid in graph_generators
diff r fee71ad457d0 r 785fec521c35 sage/graphs/graph_generators.py
 a/sage/graphs/graph_generators.py Thu Nov 19 17:15:21 2009 0800
+++ b/sage/graphs/graph_generators.py Sun Nov 29 16:18:02 2009 +0100
@@ 59,6 +59,7 @@
 LollipopGraph
 PathGraph
 StarGraph
+  ToroidalGrid2dGraph
 WheelGraph
Platonic Solids:
 TetrahedralGraph
@@ 192,6 +193,7 @@
 LollipopGraph
 PathGraph
 StarGraph
+  ToroidalGrid2dGraph
 WheelGraph
Platonic Solids:
 TetrahedralGraph
@@ 764,25 +766,58 @@
"""
return graph.Graph(sparse=True)
+ def ToroidalGrid2dGraph(self,n1,n2):
+ r"""
+ Returns a toroidal 2dimensional grid graph with `n_1n_2` nodes
+ (`n_1` rows and `n_2` columns).
+
+ The toroidal 2dimensional grid with parameters `n_1,n_2` is
+ the 2dimensional grid graph with identital parameters
+ to which are added the edges `((i,0),(i,n_21))` and
+ `((0,i),(n_11,i))`.
+
+ EXAMPLE:
+
+ The toroidal 2dimensional grid is a regular graph, while
+ the usual 2dimensional grid is not ::
+
+ sage: tgrid = graphs.ToroidalGrid2dGraph(8,9)
+ sage: print tgrid
+ Toroidal 2D Grid Graph with parameters 8,9
+ sage: grid = graphs.Grid2dGraph(8,9)
+ sage: grid.is_regular()
+ False
+ sage: tgrid.is_regular()
+ True
+ """
+
+ g = self.Grid2dGraph(n1,n2)
+
+ g.add_edges([((i,0),(i,n21)) for i in range(n1)] + [((0,i),(n11,i)) for i in range(n2)])
+
+ g.name("Toroidal 2D Grid Graph with parameters "+str(n1)+","+str(n2))
+
+ return g
+
def Grid2dGraph(self, n1, n2):
 """
 Returns a 2dimensional grid graph with n1\*n2 nodes (n1 rows and
 n2 columns).

 A 2d grid graph resembles a 2 dimensional grid. All inner nodes are
 connected to their 4 neighbors. Outer (noncorner) nodes are
 connected to their 3 neighbors. Corner nodes are connected to their
+ r"""
+ Returns a `2`dimensional grid graph with `n_1n_2` nodes (`n_1` rows and
+ `n_2` columns).
+
+ A 2d grid graph resembles a `2` dimensional grid. All inner nodes are
+ connected to their `4` neighbors. Outer (noncorner) nodes are
+ connected to their `3` neighbors. Corner nodes are connected to their
2 neighbors.
This constructor depends on NetworkX numeric labels.
PLOTTING: Upon construction, the position dictionary is filled to
override the springlayout algorithm. By convention, nodes are
 labelled in (row, column) pairs with (0, 0) in the top left corner.
+ labelled in (row, column) pairs with `(0, 0)` in the top left corner.
Edges will always be horizontal and vertical  another advantage of
filling the position dictionary.
 EXAMPLES: Construct and show a grid 2d graph Rows = 5, Columns = 7
+ EXAMPLES: Construct and show a grid 2d graph Rows = `5`, Columns = `7`
::