25
25
from sage .sandpiles .sandpile import Sandpile
26
26
from sage .graphs .graph_generators import graphs
27
27
28
- class SandpileExamples ():
28
+
29
+ class SandpileExamples :
29
30
"""
30
31
Some examples of sandpiles.
31
32
@@ -92,7 +93,7 @@ def Complete(self, n):
92
93
sage: sandpiles.Complete(3) == sandpiles.Cycle(3)
93
94
True
94
95
"""
95
- return Sandpile (graphs .CompleteGraph (n ),0 )
96
+ return Sandpile (graphs .CompleteGraph (n ), 0 )
96
97
97
98
def Cycle (self , n ):
98
99
"""
@@ -119,7 +120,7 @@ def Cycle(self, n):
119
120
(3, 0, 1),
120
121
(3, 2, 1)]
121
122
"""
122
- return Sandpile (graphs .CycleGraph (n ),0 )
123
+ return Sandpile (graphs .CycleGraph (n ), 0 )
123
124
124
125
def Diamond (self ):
125
126
"""
@@ -164,18 +165,18 @@ def Fan(self, n, deg_three_verts=False):
164
165
"""
165
166
f = graphs .WheelGraph (n )
166
167
if n > 2 :
167
- f .delete_edge (1 ,n - 1 )
168
+ f .delete_edge (1 , n - 1 )
168
169
if deg_three_verts :
169
170
f .allow_multiple_edges (True )
170
- f .add_edges ([(0 ,1 ),(0 ,n - 1 )])
171
- return Sandpile (f ,0 )
171
+ f .add_edges ([(0 , 1 ), (0 , n - 1 )])
172
+ return Sandpile (f , 0 )
172
173
elif n == 1 :
173
- return Sandpile (f ,0 )
174
+ return Sandpile (f , 0 )
174
175
elif n == 2 :
175
176
if deg_three_verts :
176
- return Sandpile ({0 :{1 :3 }, 1 :{0 :3 }})
177
+ return Sandpile ({0 : {1 : 3 }, 1 : {0 : 3 }})
177
178
else :
178
- return Sandpile (f ,0 )
179
+ return Sandpile (f , 0 )
179
180
180
181
def Grid (self , m , n ):
181
182
"""
@@ -200,11 +201,12 @@ def Grid(self, m, n):
200
201
sage: s.dict()
201
202
{(0, 0): {(1, 1): 4}, (1, 1): {(0, 0): 4}}
202
203
"""
203
- G = graphs .Grid2dGraph (m + 2 ,n + 2 )
204
+ G = graphs .Grid2dGraph (m + 2 , n + 2 )
204
205
G .allow_multiple_edges (True ) # to ensure each vertex ends up with degree 4
205
- V = [(i ,j ) for i in [0 ,m + 1 ] for j in range (n + 2 )] + [(i ,j ) for j in [0 ,n + 1 ] for i in range (m + 2 )]
206
+ V = [(i , j ) for i in [0 , m + 1 ] for j in range (n + 2 )]
207
+ V += [(i , j ) for j in [0 , n + 1 ] for i in range (m + 2 )]
206
208
G .merge_vertices (V )
207
- return Sandpile (G , (0 ,0 ))
209
+ return Sandpile (G , (0 , 0 ))
208
210
209
211
def House (self ):
210
212
"""
@@ -224,7 +226,7 @@ def House(self):
224
226
sage: s.invariant_factors()
225
227
[1, 1, 1, 11]
226
228
"""
227
- return Sandpile (graphs .HouseGraph (),0 )
229
+ return Sandpile (graphs .HouseGraph (), 0 )
228
230
229
231
def Wheel (self , n ):
230
232
"""
@@ -244,7 +246,7 @@ def Wheel(self, n):
244
246
sage: w.invariant_factors()
245
247
[1, 1, 1, 11, 11]
246
248
"""
247
- return Sandpile (graphs .WheelGraph (n ),0 )
249
+ return Sandpile (graphs .WheelGraph (n ), 0 )
248
250
249
251
250
252
sandpiles = SandpileExamples ()
0 commit comments