@@ -22,14 +22,14 @@ def is_covering_array(array, strength=None, levels=None, verbose=False, paramete
22
22
r """
23
23
Check if the input is a covering array with given strength.
24
24
25
- - ``array`` -- The Covering Array to be tested.
25
+ - ``array`` -- the Covering Array to be tested.
26
26
27
- - ``strength`` ( integer) -- The parameter `t` of the covering array,
27
+ - ``strength`` ( integer) -- the parameter `t` of the covering array,
28
28
such that in any selection of `t` columns of the array, every `t`
29
29
-tuple appears at least once. If set to None then all t > 0 are
30
30
tested to and the maximal strength is used.
31
31
32
- - ``levels`` -- The number of symbols that appear in ``array``.
32
+ - ``levels`` -- the number of symbols that appear in ``array``.
33
33
If set to None, then each unique entry in ``array`` is counted.
34
34
35
35
- ``verbose`` ( boolean) -- whether to display some information about
@@ -42,98 +42,116 @@ def is_covering_array(array, strength=None, levels=None, verbose=False, paramete
42
42
EXAMPLES::
43
43
44
44
sage: from sage. combinat. designs. designs_pyx import is_covering_array
45
- sage: C = (( 1, 1, 1, 0) ,
46
- .... : ( 1, 1, 0, 0) ,
47
- .... : ( 0, 0, 0))
45
+ sage: C = [ [ 1, 1, 1, 0] ,
46
+ .... : [ 1, 1, 0, 0 ] ,
47
+ .... : [ 0, 0, 0 ]]
48
48
sage: is_covering_array( C)
49
49
Traceback ( most recent call last) :
50
50
...
51
51
ValueError: Not all rows are the same length, row 2 is not the same length as row 0
52
52
53
- sage: from sage. combinat. designs. designs_pyx import is_covering_array
54
- sage: C = (( 0, 1, 0) ,
55
- .... : ( 1, 1, 0) ,
56
- .... : ( 1, 0, 0))
53
+ sage: C = [[0, 1, 1 ],
54
+ .... : [1, 1, 0 ],
55
+ .... : [1, 0, 1 ],
56
+ .... : [0, 0, 0, ]]
57
+ sage: is_covering_array( C,strength=4)
58
+ Traceback ( most recent call last) :
59
+ ...
60
+ ValueError: Strength must be equal or less than number of columns
61
+
62
+ sage: C = [[0, 1, 1 ],
63
+ .... : [1, 1, 1 ],
64
+ .... : [1, 0, 1 ]]
57
65
sage: is_covering_array( C,verbose=True)
58
- A 3 by 3 Covering Array with strength 0 with entries from {0, 1}
66
+ A 3 by 3 Covering Array with strength 0 with entries from a symbol set of size 2
59
67
True
60
68
61
- sage: C = (( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) ,
62
- .... : ( 0, 0, 0, 0, 1, 1, 1, 1, 1, 1) ,
63
- .... : ( 0, 1, 1, 1, 0, 0, 0, 1, 1, 1) ,
64
- .... : ( 1, 0, 1, 1, 0, 1, 1, 0, 0, 1) ,
65
- .... : ( 1, 1, 0, 1, 1, 0, 1, 0, 1, 0) ,
66
- .... : ( 1, 1, 1, 0, 1, 1, 0, 1, 2, 0))
69
+ sage: C = [ [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ,
70
+ .... : [ 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 ] ,
71
+ .... : [ 0, 1, 1, 1, 0, 0, 0, 1, 1, 1 ] ,
72
+ .... : [ 1, 0, 1, 1, 0, 1, 1, 0, 0, 1 ] ,
73
+ .... : [ 1, 1, 0, 1, 1, 0, 1, 0, 1, 0 ] ,
74
+ .... : [ 1, 1, 1, 0, 1, 1, 0, 1, 2, 0 ]]
67
75
sage: is_covering_array( C,levels=2)
68
76
Traceback ( most recent call last) :
69
77
...
70
- ValueError: array should contain integer symbols from 0 to 1
71
-
72
- sage: C = (( 1, 0, 0, 2, 0, 2, 1, 2, 2, 1, 0, 2, 2) ,
73
- .... : ( 1, 1, 0, 0, 2, 0, 2, 1, 2, 2, 1, 0, 2) ,
74
- .... : ( 1, 1, 1, 0, 0, 2, 0, 2, 1, 2, 2, 1, 0) ,
75
- .... : ( 0, 1, 1, 1, 0, 0, 2, 0, 2, 1, 2, 2, 1) ,
76
- .... : ( 2, 0, 1, 1, 1, 0, 0, 2, 0, 2, 1, 2, 2) ,
77
- .... : ( 1, 2, 0, 1, 1, 1, 0, 0, 2, 0, 2, 1, 2) ,
78
- .... : ( 1, 1, 2, 0, 1, 1, 1, 0, 0, 2, 0, 2, 1) ,
79
- ....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 2, 1, 0, 1, 0, 0) ,
100
- .... : ( 0, 1, 1, 1, 0, 2, 1, 1, 2, 1, 0, 1, 0) ,
101
- .... : ( 0, 0, 1, 1, 1, 0, 2, 1, 1, 2, 1, 0, 1) ,
102
- .... : ( 2, 0, 0, 1, 1, 1, 0, 2, 1, 1, 2, 1, 0) ,
103
- .... : ( 0, 2, 0, 0, 1, 1, 1, 0, 2, 1, 1, 2, 1) ,
104
- .... : ( 2, 0, 2, 0, 0, 1, 1, 1, 0, 2, 1, 1, 2) ,
105
- .... : ( 1, 2, 0, 2, 0, 0, 1, 1, 1, 0, 2, 1, 1) ,
106
- .... : ( 2, 1, 2, 0, 2, 0, 0, 1, 1, 1, 0, 2, 1) ,
107
- .... : ( 2, 2, 1, 2, 0, 2, 0, 0, 1, 1, 1, 0, 2) ,
108
- .... : ( 1, 2, 2, 1, 2, 0, 2, 0, 0, 1, 1, 1, 0) ,
109
- .... : ( 0, 1, 2, 2, 1, 2, 0, 2, 0, 0, 1, 1, 1) ,
110
- .... : ( 2, 0, 1, 2, 2, 1, 2, 0, 2, 0, 0, 1, 1) ,
111
- .... : ( 2, 2, 0, 1, 2, 2, 1, 2, 0, 2, 0, 0, 1) ,
112
- .... : ( 2, 2, 2, 0, 1, 2, 2, 1, 2, 0, 2, 0, 0) ,
113
- .... : ( 0, 2, 2, 2, 0, 1, 2, 2, 1, 2, 0, 2, 0) ,
114
- .... : ( 0, 0, 2, 2, 2, 0, 1, 2, 2, 1, 2, 0, 2) ,
115
- .... : ( 1, 0, 0, 2, 2, 2, 0, 1, 2, 2, 1, 2, 0) ,
116
- .... : ( 0, 1, 0, 0, 2, 2, 2, 0, 1, 2, 2, 1, 2) ,
117
- .... : ( 1, 0, 1, 0, 0, 2, 2, 2, 0, 1, 2, 2, 1) ,
118
- .... : ( 2, 1, 0, 1, 0, 0, 2, 2, 2, 0, 1, 2, 2) ,
119
- .... : ( 1, 2, 1, 0, 1, 0, 0, 2, 2, 2, 0, 1, 2) ,
120
- .... : ( 1, 1, 2, 1, 0, 1, 0, 0, 2, 2, 2, 0, 1) ,
121
- .... : ( 2, 1, 1, 2, 1, 0, 1, 0, 0, 2, 2, 2, 0) ,
122
- .... : ( 0, 2, 1, 1, 2, 1, 0, 1, 0, 0, 2, 2, 2) ,
123
- .... : ( 1, 0, 2, 1, 1, 2, 1, 0, 1, 0, 0, 2, 2) ,
124
- .... : ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
78
+ ValueError: Array should contain integer symbols from 0 to 1
79
+
80
+ sage: C = [ [ 1, 0, 0, 2, 0, 2, 1, 2, 2, 1, 0, 2, 2] ,
81
+ .... : [ 1, 1, 0, 0, 2, 0, 2, 1, 2, 2, 1, 0, 2 ] ,
82
+ .... : [ 1, 1, 1, 0, 0, 2, 0, 2, 1, 2, 2, 1, 0 ] ,
83
+ .... : [ 0, 1, 1, 1, 0, 0, 2, 0, 2, 1, 2, 2, 1 ] ,
84
+ .... : [ 2, 0, 1, 1, 1, 0, 0, 2, 0, 2, 1, 2, 2 ] ,
85
+ .... : [ 1, 2, 0, 1, 1, 1, 0, 0, 2, 0, 2, 1, 2 ] ,
86
+ .... : [ 1, 1, 2, 0, 1, 1, 1, 0, 0, 2, 0, 2, 1 ] ,
87
+ .... : [ 2, 1, 1, 2, 0, 1, 1, 1, 0, 0, 2, 0, 2 ] ,
88
+ .... : [ 1, 2, 1, 1, 2, 0, 1, 1, 1, 0, 0, 2, 0 ] ,
89
+ .... : [ 0, 1, 2, 1, 1, 2, 0, 1, 1, 1, 0, 0, 2 ] ,
90
+ .... : [ 1, 0, 1, 2, 1, 1, 2, 0, 1, 1, 1, 0, 0 ] ,
91
+ .... : [ 0, 1, 0, 1, 2, 1, 1, 2, 0, 1, 1, 1, 0 ] ,
92
+ .... : [ 0, 0, 1, 0, 1, 2, 1, 1, 2, 0, 1, 1, 1 ] ,
93
+ .... : [ 2, 0, 0, 1, 0, 1, 2, 1, 1, 2, 0, 1, 1 ] ,
94
+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, 0, 0, 0 ]]
125
133
sage: is_covering_array( C,parameters=True)
126
134
( True, ( 53, 3, 13, 3))
127
135
136
+ sage: C = [[1, 0, 1, 1, 2, 0, 2, 2 ],
137
+ .... : [2, 1, 0, 1, 1, 2, 0, 2 ],
138
+ .... : [2, 2, 1, 0, 1, 1, 2, 0 ],
139
+ .... : [0, 2, 2, 1, 0, 1, 1, 2 ],
140
+ .... : [2, 0, 2, 2, 1, 0, 1, 1 ],
141
+ .... : [1, 2, 0, 2, 2, 1, 0, 1 ],
142
+ .... : [1, 1, 2, 0, 2, 2, 1, 0 ],
143
+ .... : [0, 1, 1, 2, 0, 2, 2, 1 ]]
144
+ sage: is_covering_array( C,strength=2,parameters=True)
145
+ ( False, ( 8, 0, 8, 3))
146
+
128
147
"""
129
148
from itertools import product, combinations
130
- from sage.rings.integer import Integer
131
149
132
150
if levels is None :
133
- symbol_set = {x for l in array for x in l}
134
- levels = len (symbol_set )
151
+ symbol_list = list ( {x for l in array for x in l})
152
+ levels = len (symbol_list )
135
153
else :
136
- symbol_set = { num for num in range (levels)}
154
+ symbol_list = [ num for num in range (levels)]
137
155
138
156
number_rows = len (array)
139
157
number_columns = len (array[0 ])
@@ -143,28 +161,28 @@ def is_covering_array(array, strength=None, levels=None, verbose=False, paramete
143
161
wstrength = 1
144
162
else :
145
163
if strength > number_columns:
146
- raise ValueError (" strength must be equal or less than number of columns" )
164
+ raise ValueError (" Strength must be equal or less than number of columns" )
147
165
wstrength = strength
148
166
149
167
for row in array:
150
168
if len (row) != number_columns:
151
169
raise ValueError (" Not all rows are the same length, row {} is not the same length as row 0" .format(array.index(row)))
152
170
else :
153
171
for entry in row:
154
- if type (entry) != Integer or entry < - 1 or entry >= levels:
155
- raise ValueError (" array should contain integer symbols from 0 to {}" .format(levels- 1 ))
172
+ if int (entry) != entry or entry < - 1 or entry >= levels:
173
+ raise ValueError (" Array should contain integer symbols from 0 to {}" .format(levels- 1 ))
156
174
157
175
finished = False
176
+ result = True
158
177
# If no strength inputted, try increasing values for t until one
159
178
# does not work. If strength is inputted end after one check
160
179
while finished is False :
161
180
# Iterate over every possible selections of t columns, and
162
181
# count the t-tuples appearing in each selection
163
182
for comb in combinations(range (number_columns), wstrength):
164
- tuple_dictionary = {item: 0 for item in product(symbol_set , repeat = wstrength)}
183
+ tuple_dictionary = {item: 0 for item in product(symbol_list , repeat = wstrength)}
165
184
for row in array:
166
185
tuple_dictionary[tuple ([row[ti] for ti in comb])] += 1
167
-
168
186
# Check if any t-tuple is not covered in current columns
169
187
if 0 in tuple_dictionary.values():
170
188
if strength is None :
@@ -177,15 +195,15 @@ def is_covering_array(array, strength=None, levels=None, verbose=False, paramete
177
195
finished = True
178
196
break
179
197
180
- if strength is None and finished is False and wstrength < number_columns :
181
- wstrength += 1
182
- else :
183
- result = True
184
- finished = True
185
- break
198
+ if finished is False :
199
+ if strength is None and wstrength < number_columns:
200
+ wstrength += 1
201
+ else :
202
+ finished = True
203
+ break
186
204
187
205
if verbose:
188
- print (' A {} by {} Covering Array with strength {} with entries from {}' .format(number_rows,number_columns,wstrength,symbol_set ))
206
+ print (' A {} by {} Covering Array with strength {} with entries from a symbol set of size {}' .format(number_rows,number_columns,wstrength,levels ))
189
207
190
208
if parameters:
191
209
return (result, (number_rows, wstrength, number_columns, levels))
0 commit comments