24
24
---------
25
25
"""
26
26
27
- #* ****************************************************************************
27
+ # ****************************************************************************
28
28
# This program is free software: you can redistribute it and/or modify
29
29
# it under the terms of the GNU General Public License as published by
30
30
# the Free Software Foundation, either version 2 of the License, or
31
31
# (at your option) any later version.
32
- # http ://www.gnu.org/licenses/
33
- #* ****************************************************************************
32
+ # https ://www.gnu.org/licenses/
33
+ # ****************************************************************************
34
34
35
35
from sage .arith .misc import is_prime_power
36
- from sage .misc .unknown import Unknown
36
+ from sage .misc .unknown import Unknown
37
37
from .incidence_structures import IncidenceStructure
38
38
39
- def group_divisible_design (v ,K ,G ,existence = False ,check = False ):
39
+
40
+ def group_divisible_design (v , K , G , existence = False , check = False ):
40
41
r"""
41
42
Return a `(v,K,G)`-Group Divisible Design.
42
43
@@ -90,36 +91,31 @@ def group_divisible_design(v,K,G,existence=False,check=False):
90
91
blocks = None
91
92
92
93
# from a (v+1,k,1)-BIBD
93
- if (len (G ) == 1 and
94
- len (K ) == 1 and
95
- G [0 ]+ 1 in K ):
94
+ if len (G ) == 1 == len (K ) and G [0 ] + 1 in K :
96
95
from .bibd import balanced_incomplete_block_design
97
96
k = K [0 ]
98
97
if existence :
99
- return balanced_incomplete_block_design (v + 1 , k , existence = True )
100
- BIBD = balanced_incomplete_block_design (v + 1 , k )
98
+ return balanced_incomplete_block_design (v + 1 , k , existence = True )
99
+ BIBD = balanced_incomplete_block_design (v + 1 , k )
101
100
groups = [[x for x in S if x != v ] for S in BIBD if v in S ]
102
- d = {p :i for i ,p in enumerate (sum (groups ,[]))}
101
+ d = {p : i for i , p in enumerate (sum (groups , []))}
103
102
d [v ] = v
104
103
BIBD .relabel (d )
105
- groups = [list (range ((k - 1 )* i ,(k - 1 )* (i + 1 ))) for i in range (v // (k - 1 ))]
104
+ groups = [list (range ((k - 1 ) * i , (k - 1 ) * (i + 1 )))
105
+ for i in range (v // (k - 1 ))]
106
106
blocks = [S for S in BIBD if v not in S ]
107
107
108
108
# (v,{4},{2})-GDD
109
- elif (v % 2 == 0 and
110
- K == [4 ] and
111
- G == [2 ] and
112
- GDD_4_2 (v // 2 ,existence = True )):
109
+ elif (v % 2 == 0 and K == [4 ] and
110
+ G == [2 ] and GDD_4_2 (v // 2 , existence = True )):
113
111
if existence :
114
112
return True
115
- return GDD_4_2 (v // 2 , check = check )
113
+ return GDD_4_2 (v // 2 , check = check )
116
114
117
115
# From a TD(k,g)
118
- elif (len (G ) == 1 and
119
- len (K ) == 1 and
120
- K [0 ]* G [0 ] == v ):
116
+ elif (len (G ) == 1 == len (K ) and K [0 ] * G [0 ] == v ):
121
117
from .orthogonal_arrays import transversal_design
122
- return transversal_design (k = K [0 ],n = G [0 ],existence = existence )
118
+ return transversal_design (k = K [0 ], n = G [0 ], existence = existence )
123
119
124
120
if blocks :
125
121
return GroupDivisibleDesign (v ,
@@ -134,7 +130,8 @@ def group_divisible_design(v,K,G,existence=False,check=False):
134
130
return Unknown
135
131
raise NotImplementedError
136
132
137
- def GDD_4_2 (q ,existence = False ,check = True ):
133
+
134
+ def GDD_4_2 (q , existence = False , check = True ):
138
135
r"""
139
136
Return a `(2q,\{4\},\{2\})`-GDD for `q` a prime power with `q\equiv 1\pmod{6}`.
140
137
@@ -180,26 +177,27 @@ def GDD_4_2(q,existence=False,check=True):
180
177
return True
181
178
182
179
from sage .rings .finite_rings .finite_field_constructor import FiniteField as GF
183
- G = GF (q ,'x' )
180
+ G = GF (q , 'x' )
184
181
w = G .primitive_element ()
185
182
e = w ** ((q - 1 ) // 3 )
186
183
187
184
# A first parallel class is defined. G acts on it, which yields all others.
188
- first_class = [[(0 ,0 ),(1 ,w ** i ),(1 ,e * w ** i ),(1 ,e * e * w ** i )]
185
+ first_class = [[(0 , 0 ), (1 , w ** i ), (1 , e * w ** i ), (1 , e * e * w ** i )]
189
186
for i in range ((q - 1 ) // 6 )]
190
187
191
- label = {p :i for i ,p in enumerate (G )}
192
- classes = [[[2 * label [x [1 ]+ g ] + (x [0 ]+ j ) % 2 for x in S ]
188
+ label = {p : i for i , p in enumerate (G )}
189
+ classes = [[[2 * label [x [1 ] + g ] + (x [0 ] + j ) % 2 for x in S ]
193
190
for S in first_class ]
194
191
for g in G for j in range (2 )]
195
192
196
- return GroupDivisibleDesign (2 * q ,
197
- groups = [[i ,i + 1 ] for i in range (0 ,2 * q ,2 )],
198
- blocks = sum (classes ,[]),
199
- K = [4 ],
200
- G = [2 ],
201
- check = check ,
202
- copy = False )
193
+ return GroupDivisibleDesign (2 * q ,
194
+ groups = [[i , i + 1 ] for i in range (0 , 2 * q , 2 )],
195
+ blocks = sum (classes , []),
196
+ K = [4 ],
197
+ G = [2 ],
198
+ check = check ,
199
+ copy = False )
200
+
203
201
204
202
class GroupDivisibleDesign (IncidenceStructure ):
205
203
r"""
@@ -261,9 +259,9 @@ class GroupDivisibleDesign(IncidenceStructure):
261
259
sage: GDD = GroupDivisibleDesign('abcdefghiklm',None,D)
262
260
sage: sorted(GDD.groups())
263
261
[['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ['k', 'l', 'm']]
264
-
265
262
"""
266
- def __init__ (self , points , groups , blocks , G = None , K = None , lambd = 1 , check = True , copy = True ,** kwds ):
263
+ def __init__ (self , points , groups , blocks , G = None , K = None , lambd = 1 ,
264
+ check = True , copy = True , ** kwds ):
267
265
r"""
268
266
Constructor function
269
267
@@ -286,16 +284,17 @@ def __init__(self, points, groups, blocks, G=None, K=None, lambd=1, check=True,
286
284
check = False ,
287
285
** kwds )
288
286
289
- if (groups is None or
290
- (copy is False and self ._point_to_index is None )):
287
+ if (groups is None or (copy is False and self ._point_to_index is None )):
291
288
self ._groups = groups
292
289
elif self ._point_to_index is None :
293
290
self ._groups = [g [:] for g in groups ]
294
291
else :
295
292
self ._groups = [[self ._point_to_index [x ] for x in g ] for g in groups ]
296
293
297
294
if check or groups is None :
298
- is_gdd = is_group_divisible_design (self ._groups ,self ._blocks ,self .num_points (),G ,K ,lambd ,verbose = 1 )
295
+ is_gdd = is_group_divisible_design (self ._groups , self ._blocks ,
296
+ self .num_points (), G , K ,
297
+ lambd , verbose = 1 )
299
298
assert is_gdd
300
299
if groups is None :
301
300
self ._groups = is_gdd [1 ]
@@ -337,7 +336,7 @@ def groups(self):
337
336
338
337
def __repr__ (self ):
339
338
r"""
340
- Returns a string that describes self
339
+ Return a string that describes `` self``.
341
340
342
341
EXAMPLES::
343
342
@@ -347,16 +346,15 @@ def __repr__(self):
347
346
sage: GDD = GroupDivisibleDesign(40,groups,TD); GDD
348
347
Group Divisible Design on 40 points of type 10^4
349
348
"""
349
+ group_sizes = [len (g ) for g in self ._groups ]
350
350
351
- group_sizes = [len (_ ) for _ in self ._groups ]
352
-
353
- gdd_type = ["{}^{}" .format (s ,group_sizes .count (s ))
354
- for s in sorted (set (group_sizes ))]
351
+ gdd_type = ("{}^{}" .format (s , group_sizes .count (s ))
352
+ for s in sorted (set (group_sizes )))
355
353
gdd_type = "." .join (gdd_type )
356
354
357
355
if not gdd_type :
358
356
gdd_type = "1^0"
359
357
360
358
v = self .num_points ()
361
359
362
- return "Group Divisible Design on {} points of type {}" .format (v ,gdd_type )
360
+ return "Group Divisible Design on {} points of type {}" .format (v , gdd_type )
0 commit comments