12
12
13
13
REFERENCES:
14
14
15
- .. [Colb2004] C.J. Colbourn. “Combinatorial aspects of covering arrays”.
16
- Matematiche (Catania) 59 (2004), pp. 125–172.
15
+ - [Colb2004]_
17
16
17
+ - [Sher2006]_
18
18
19
- .. [Sher2006] G.B. Sherwood, S.S Martirosyan, and C.J. Colbourn,
20
- "Covering arrays of higher strength from permutation
21
- vectors". J. Combin. Designs, 14 (2006) pp. 202-213.
22
-
23
- .. [Wal2007] R.A. Walker II, and C.J. Colbourn, "Perfect Hash Families:
24
- Constructions and Existence". J. Math. Crypt. 1 (2007),
25
- pp.125-150
19
+ - [Wal2007]_
26
20
27
21
AUTHORS:
28
22
47
41
48
42
from sage .rings .finite_rings .finite_field_constructor import GF
49
43
from sage .structure .sage_object import SageObject
50
- from sage .structure .richcmp import richcmp
51
-
44
+ from sage .structure .richcmp import richcmp , richcmp_method
52
45
46
+ @richcmp_method
53
47
class CoveringArray (SageObject ):
54
48
r"""
55
49
Covering Array (CA)
56
50
57
51
INPUT:
58
52
59
- - ``Array`` -- The N by k array itself stored as a tuple of tuples.
60
- The N and k parameters are derived from this inputted array
53
+ - ``array`` -- The `N` by `k` array itself stored as a tuple of
54
+ tuples. The `N` and `k` parameters are derived from this inputted
55
+ array.
61
56
62
- - ``SymbolSet `` -- The collection of symbols that is used in
63
- ``Array ``. If left blank, then a symbol set will be assumed by
64
- checking for each unique entry in the given ``Array ``. In such a
65
- case it will be stored as a list of symbols but any appropriate
66
- object may be used as long as it has `len()` as a method
57
+ - ``symbol_set `` -- The collection of symbols that is used in
58
+ ``array ``. If left blank, then a symbol set will be assumed by
59
+ checking for each unique entry in the given ``array ``. In such a
60
+ case it will be stored as a tuple of symbols but any appropriate
61
+ object may be used as long as it has `` len()`` as a method.
67
62
68
63
EXAMPLES::
69
64
@@ -74,7 +69,7 @@ class CoveringArray(SageObject):
74
69
....: ('b', 'a', 'a', 'a'),
75
70
....: ('b', 'b', 'b', 'b'))
76
71
sage: CoveringArray(C)
77
- A 5 by 4 Covering Array with entries from [ 'a', 'b']
72
+ A 5 by 4 Covering Array with entries from ( 'a', 'b')
78
73
79
74
sage: C = ((0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
80
75
....: (1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
@@ -89,8 +84,8 @@ class CoveringArray(SageObject):
89
84
....: (0, 1, 0, 1, 1, 0, 0, 1, 0, 0),
90
85
....: (1, 0, 0, 0, 0, 0, 0, 1, 1, 1),
91
86
....: (0, 1, 0, 0, 0, 1, 1, 1, 0, 1))
92
- sage: CoveringArray(C,[ 0, 1] )
93
- A 13 by 10 Covering Array with entries from [ 0, 1]
87
+ sage: CoveringArray(C,( 0, 1) )
88
+ A 13 by 10 Covering Array with entries from ( 0, 1)
94
89
95
90
sage: C = ((0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
96
91
....: (0, 0, 0, 0, 1, 1, 1, 1, 1, 1),
@@ -109,12 +104,12 @@ class CoveringArray(SageObject):
109
104
....: (1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0),
110
105
....: (1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0))
111
106
sage: CoveringArray(C)
112
- A 7 by 15 Covering Array with entries from [ 0, 1]
107
+ A 7 by 15 Covering Array with entries from ( 0, 1)
113
108
"""
114
109
115
- def __init__ (self , Array , SymbolSet = None ):
110
+ def __init__ (self , array , symbol_set = None ):
116
111
r"""
117
- Constructor function
112
+ Constructor function.
118
113
119
114
EXAMPLES::
120
115
@@ -125,7 +120,7 @@ def __init__(self, Array, SymbolSet=None):
125
120
....: ('b', 'a', 'a', 'a'),
126
121
....: ('b', 'b', 'b', 'b'))
127
122
sage: CoveringArray(C)
128
- A 5 by 4 Covering Array with entries from [ 'a', 'b']
123
+ A 5 by 4 Covering Array with entries from ( 'a', 'b')
129
124
130
125
sage: C = ((0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
131
126
....: (1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
@@ -140,8 +135,8 @@ def __init__(self, Array, SymbolSet=None):
140
135
....: (0, 1, 0, 1, 1, 0, 0, 1, 0, 0),
141
136
....: (1, 0, 0, 0, 0, 0, 0, 1, 1, 1),
142
137
....: (0, 1, 0, 0, 0, 1, 1, 1, 0, 1))
143
- sage: CoveringArray(C,[ 0, 1] )
144
- A 13 by 10 Covering Array with entries from [ 0, 1]
138
+ sage: CoveringArray(C,( 0, 1) )
139
+ A 13 by 10 Covering Array with entries from ( 0, 1)
145
140
146
141
sage: C = ((0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
147
142
....: (0, 0, 0, 0, 1, 1, 1, 1, 1, 1),
@@ -160,35 +155,35 @@ def __init__(self, Array, SymbolSet=None):
160
155
....: (1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0),
161
156
....: (1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0))
162
157
sage: CoveringArray(C)
163
- A 7 by 15 Covering Array with entries from [ 0, 1]
158
+ A 7 by 15 Covering Array with entries from ( 0, 1)
164
159
"""
165
160
#From the array input, grab the dimensions of the array
166
- N = len (Array )
167
- self .__n = N
168
- k = len (Array [0 ])
169
- self .__k = k
161
+ N = len (array )
162
+ self ._n = N
163
+ k = len (array [0 ])
164
+ self ._k = k
170
165
171
- #Array input is a tuple of tuples, the first thing to do is to
166
+ #array input is a tuple of tuples, the first thing to do is to
172
167
#sort the tuples lexicographically increasing
173
- L = list (Array )
168
+ L = list (array )
174
169
L .sort ()
175
- SortedArray = tuple (L )
176
- self .__array = SortedArray
170
+ self ._array = tuple (L )
177
171
178
- for row in Array :
179
- assert len (row ) == len (Array [0 ]), "Not all rows have same length"
172
+ for row in array :
173
+ assert len (row ) == len (array [0 ]), "Not all rows have same length"
180
174
181
175
#If no symbol set is given, then it may be assumed from what
182
176
#symbols are in the array by flattening the array and counting
183
177
#the number of unique entries.
184
- if SymbolSet is None :
185
- SymbolSet = list ({x for l in Array for x in l })
186
- SymbolSet .sort ()
187
- self .__sset = SymbolSet
178
+ if symbol_set is None :
179
+ symbol_set = list ({x for l in array for x in l })
180
+ symbol_set .sort ()
181
+ symbol_set = tuple (symbol_set )
182
+ self ._sset = symbol_set
188
183
189
- def numrows (self ):
184
+ def number_rows (self ):
190
185
r"""
191
- Return the number of rows, `N`, of the covering array
186
+ Return the number of rows, `N`, of the covering array.
192
187
193
188
EXAMPLES::
194
189
@@ -199,14 +194,14 @@ def numrows(self):
199
194
....: (0, 1, 1, 1),
200
195
....: (0, 0, 0, 0))
201
196
sage: CA = CoveringArray(C,GF(2))
202
- sage: CA.numrows ()
197
+ sage: CA.number_rows ()
203
198
5
204
199
"""
205
- return self .__n
200
+ return self ._n
206
201
207
- def numcols (self ):
202
+ def number_columns (self ):
208
203
r"""
209
- Returns the number of columns, `k`, of the covering array
204
+ Return the number of columns, `k`, of the covering array.
210
205
211
206
EXAMPLES::
212
207
@@ -217,12 +212,12 @@ def numcols(self):
217
212
....: (0, 1, 1, 1),
218
213
....: (0, 0, 0, 0))
219
214
sage: CA = CoveringArray(C,GF(2))
220
- sage: CA.numcols ()
215
+ sage: CA.number_columns ()
221
216
4
222
217
"""
223
- return self .__k
218
+ return self ._k
224
219
225
- def symbolset (self ):
220
+ def symbol_set (self ):
226
221
r"""
227
222
Return the symbol set of the array.
228
223
@@ -235,13 +230,13 @@ def symbolset(self):
235
230
....: (0, 1, 1, 1),
236
231
....: (0, 0, 0, 0))
237
232
sage: CA = CoveringArray(C,GF(2))
238
- sage: CA.symbolset ()
233
+ sage: CA.symbol_set ()
239
234
Finite Field of size 2
240
235
sage: CA = CoveringArray(C)
241
- sage: CA.symbolset ()
242
- [ 0, 1]
236
+ sage: CA.symbol_set ()
237
+ ( 0, 1)
243
238
"""
244
- return self .__sset
239
+ return self ._sset
245
240
246
241
def is_covering_array (self ,strength ):
247
242
r"""
@@ -319,14 +314,13 @@ def is_covering_array(self,strength):
319
314
True
320
315
"""
321
316
tupledict = {}
322
- a = [ttuple for ttuple in itertools .product (self .symbolset () ,
317
+ a = [ttuple for ttuple in itertools .product (self ._sset ,
323
318
repeat = strength )]
324
319
for item in a :
325
320
tupledict .update ({item :0 })
326
- for comb in itertools .combinations (range (self .numcols ()),
327
- strength ):
321
+ for comb in itertools .combinations (range (self ._k ), strength ):
328
322
wdict = copy .deepcopy (tupledict )
329
- for row in self .__array :
323
+ for row in self ._array :
330
324
wdict [tuple ([row [ti ] for ti in comb ])] += 1
331
325
if 0 in wdict .values ():
332
326
return False
@@ -434,12 +428,12 @@ def levels(self):
434
428
sage: CA.levels()
435
429
2
436
430
"""
437
- return len (self .__sset )
431
+ return len (self ._sset )
438
432
439
433
def array_representation (self ):
440
434
r"""
441
435
Return the covering array as a tuple of tuples, the output is
442
- such that each row of the array is sorted in lexicographic order
436
+ such that each row of the array is sorted in lexicographic order.
443
437
444
438
EXAMPLES::
445
439
@@ -454,11 +448,11 @@ def array_representation(self):
454
448
((0, 0, 0, 0), (0, 1, 1, 1), (1, 0, 1, 1), (1, 1, 0, 1),
455
449
(1, 1, 1, 0))
456
450
"""
457
- return self .__array
451
+ return self ._array
458
452
459
453
def _repr_ (self ):
460
454
r"""
461
- Returns a string that describes self
455
+ Return a string that describes self.
462
456
463
457
EXAMPLES::
464
458
@@ -469,7 +463,7 @@ def _repr_(self):
469
463
....: ('b', 'a', 'a', 'a'),
470
464
....: ('b', 'b', 'b', 'b'))
471
465
sage: CoveringArray(C)
472
- A 5 by 4 Covering Array with entries from [ 'a', 'b']
466
+ A 5 by 4 Covering Array with entries from ( 'a', 'b')
473
467
474
468
sage: C = ((0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
475
469
....: (1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
@@ -484,8 +478,8 @@ def _repr_(self):
484
478
....: (0, 1, 0, 1, 1, 0, 0, 1, 0, 0),
485
479
....: (1, 0, 0, 0, 0, 0, 0, 1, 1, 1),
486
480
....: (0, 1, 0, 0, 0, 1, 1, 1, 0, 1))
487
- sage: CoveringArray(C,[ 0, 1] )
488
- A 13 by 10 Covering Array with entries from [ 0, 1]
481
+ sage: CoveringArray(C,( 0, 1) )
482
+ A 13 by 10 Covering Array with entries from ( 0, 1)
489
483
490
484
sage: C = ((0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
491
485
....: (0, 0, 0, 0, 1, 1, 1, 1, 1, 1),
@@ -504,14 +498,14 @@ def _repr_(self):
504
498
....: (1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0),
505
499
....: (1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0))
506
500
sage: CoveringArray(C)
507
- A 7 by 15 Covering Array with entries from [ 0, 1]
501
+ A 7 by 15 Covering Array with entries from ( 0, 1)
508
502
"""
509
503
return 'A {} by {} Covering Array with entries from {}' .format (
510
- self .numrows () , self .numcols () , self .symbolset () )
504
+ self ._n , self ._k , self ._sset )
511
505
512
506
def pp (self ):
513
507
r"""
514
- Prints the covering array in a format easy for users to read
508
+ Prints the covering array in a format easy for users to read.
515
509
516
510
EXAMPLES::
517
511
@@ -533,12 +527,12 @@ def pp(self):
533
527
(1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0)
534
528
(1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0)
535
529
"""
536
- for i in self .__array :
530
+ for i in self ._array :
537
531
print (str (i ))
538
532
539
533
def __hash__ (self ):
540
534
r"""
541
- Hashs the tuple of tuples and all tuples inside
535
+ Hashs the tuple of tuples and all tuples inside.
542
536
543
537
EXAMPLES::
544
538
@@ -554,11 +548,10 @@ def __hash__(self):
554
548
sage: hash(CA)
555
549
4367534393624660384
556
550
"""
557
- return hash ((self .array_representation (), tuple ( self . symbolset ())))
558
-
551
+ return hash ((self .array_representation (),
552
+ tuple ( self . symbol_set ())))
559
553
560
- '''
561
- def _richcmp_(self, other, op):
554
+ def __richcmp__ (self , other , op ):
562
555
r"""
563
556
Do the comparison.
564
557
@@ -595,5 +588,5 @@ def _richcmp_(self, other, op):
595
588
sage: CA1 < CA2
596
589
False
597
590
"""
598
- return richcmp(self.array_representation(), other.array_representation(), op)
599
- '''
591
+ return richcmp (self .array_representation (),
592
+ other . array_representation (), op )
0 commit comments