Skip to content

Commit 93d1dfd

Browse files
author
Release Manager
committed
Trac #30107: Fix docstring failures in designs.balanced_incomplete_block_design with use_LJCR=True
The use of `use_LJCR=True` in `designs.balanced_incomplete_block_design` give rise to few issues. 1. The returned object has type `IncidenceStructure` instead of `BalancedIncompleteBlockDesign` 2. A `ValueError` exception can be raised if the parameters searched are not in the database Example for 2: {{{ sage: designs.balanced_incomplete_block_design(100,10,1,use_LJCR=True) Traceback (most recent call last): ... ValueError: no (100, 10, 2) covering design in database }}} In addition to the above, the docstring tests that are meant to test the use of `use_LJCR=True` are not actually testing the LJCR online database. URL: https://trac.sagemath.org/30107 Reported by: gh-Ivo-Maffei Ticket author(s): Ivo Maffei Reviewer(s): Dima Pasechnik, Samuel Lelièvre
2 parents feb63c9 + 39e147b commit 93d1dfd

File tree

1 file changed

+35
-31
lines changed

1 file changed

+35
-31
lines changed

src/sage/combinat/designs/bibd.py

+35-31
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ def balanced_incomplete_block_design(v, k, lambd=1, existence=False, use_LJCR=Fa
158158
(66,6,1)-Balanced Incomplete Block Design
159159
sage: B.blocks() # optional - internet
160160
[[0, 1, 2, 3, 4, 65], [0, 5, 22, 32, 38, 58], [0, 6, 21, 30, 43, 48], ...
161-
sage: designs.balanced_incomplete_block_design(66, 6, 1, use_LJCR=True) # optional - internet
162-
(66,6,1)-Balanced Incomplete Block Design
163161
sage: designs.balanced_incomplete_block_design(216, 6, 1)
164162
Traceback (most recent call last):
165163
...
@@ -240,12 +238,12 @@ def balanced_incomplete_block_design(v, k, lambd=1, existence=False, use_LJCR=Fa
240238
if v == 1:
241239
if existence:
242240
return True
243-
return BalancedIncompleteBlockDesign(v, [], check=False)
241+
return BIBD(v, [], check=False)
244242

245243
if k == v:
246244
if existence:
247245
return True
248-
return BalancedIncompleteBlockDesign(v, [list(range(v)) for _ in range(lambd)],lambd=lambd, check=False, copy=False)
246+
return BIBD(v, [list(range(v)) for _ in range(lambd)],lambd=lambd, check=False, copy=False)
249247

250248
# Non-existence of BIBD
251249
if (v < k or
@@ -273,62 +271,70 @@ def balanced_incomplete_block_design(v, k, lambd=1, existence=False, use_LJCR=Fa
273271
if k == 2:
274272
if existence:
275273
return True
276-
return BalancedIncompleteBlockDesign(v, [[x, y] for _ in range(lambd) for x in range(v) for y in range(x+1, v) if x != y], lambd=lambd, check=False, copy=True)
274+
return BIBD(v, [[x, y] for _ in range(lambd) for x in range(v) for y in range(x+1, v) if x != y], lambd=lambd, check=False, copy=True)
277275
if k == 3 and lambd == 1:
278276
if existence:
279277
return v%6 == 1 or v%6 == 3
280278
return steiner_triple_system(v)
281279
if k == 4 and lambd == 1:
282280
if existence:
283281
return v%12 == 1 or v%12 == 4
284-
return BalancedIncompleteBlockDesign(v, v_4_1_BIBD(v), copy=False)
282+
return BIBD(v, v_4_1_BIBD(v), copy=False)
285283
if k == 5 and lambd == 1:
286284
if existence:
287285
return v%20 == 1 or v%20 == 5
288-
return BalancedIncompleteBlockDesign(v, v_5_1_BIBD(v), copy=False)
286+
return BIBD(v, v_5_1_BIBD(v), copy=False)
289287

290288
from .difference_family import difference_family
291289
from .database import BIBD_constructions
292290

293291
if (v, k, lambd) in BIBD_constructions:
294292
if existence:
295293
return True
296-
return BalancedIncompleteBlockDesign(v,BIBD_constructions[(v, k, lambd)](), lambd=lambd, copy=False)
294+
return BIBD(v,BIBD_constructions[(v, k, lambd)](), lambd=lambd, copy=False)
297295
if lambd == 1 and BIBD_from_arc_in_desarguesian_projective_plane(v, k, existence=True):
298296
if existence:
299297
return True
300298
B = BIBD_from_arc_in_desarguesian_projective_plane(v, k)
301-
return BalancedIncompleteBlockDesign(v, B, copy=False)
299+
return BIBD(v, B, copy=False)
302300
if lambd == 1 and BIBD_from_TD(v, k, existence=True) is True:
303301
if existence:
304302
return True
305-
return BalancedIncompleteBlockDesign(v, BIBD_from_TD(v, k), copy=False)
303+
return BIBD(v, BIBD_from_TD(v, k), copy=False)
306304
if lambd == 1 and v == (k-1)**2+k and is_prime_power(k-1):
307305
if existence:
308306
return True
309307
from .block_design import projective_plane
310-
return BalancedIncompleteBlockDesign(v, projective_plane(k-1),copy=False)
308+
return BIBD(v, projective_plane(k-1),copy=False)
311309
if difference_family(v, k, l=lambd, existence=True) is True:
312310
if existence:
313311
return True
314312
G, D = difference_family(v, k, l=lambd)
315-
return BalancedIncompleteBlockDesign(v, BIBD_from_difference_family(G, D, check=False), lambd=lambd, copy=False)
313+
return BIBD(v, BIBD_from_difference_family(G, D, check=False), lambd=lambd, copy=False)
316314
if lambd == 1 and use_LJCR:
317315
from .covering_design import best_known_covering_design_www
318-
B = best_known_covering_design_www(v, k, 2)
319-
320-
# Is it a BIBD or just a good covering ?
321-
expected_n_of_blocks = binomial(v, 2)//binomial(k, 2)
322-
if B.low_bd() > expected_n_of_blocks:
323-
if existence:
324-
return False
325-
raise EmptySetError("There exists no ({},{},{})-BIBD".format(v, k, lambd))
326-
B = B.incidence_structure()
327-
if B.num_blocks() == expected_n_of_blocks:
328-
if existence:
329-
return True
330-
else:
331-
return B
316+
values_in_db = False
317+
try:
318+
B = best_known_covering_design_www(v, k, 2)
319+
values_in_db = True
320+
except ValueError:
321+
# the parameters are not in the LJCR database
322+
pass
323+
324+
if values_in_db:
325+
# Is it a BIBD or just a good covering?
326+
expected_n_of_blocks = binomial(v, 2) // binomial(k, 2)
327+
if B.low_bd() > expected_n_of_blocks:
328+
if existence:
329+
return False
330+
raise EmptySetError(f"there exists no ({v},{k},{lambd})-BIBD")
331+
B = B.incidence_structure()
332+
if B.num_blocks() == expected_n_of_blocks:
333+
if existence:
334+
return True
335+
else:
336+
return BIBD(B.ground_set(), B.blocks(), k=k, lambd=1, copy=False)
337+
332338

333339
if ( (k+lambd)*(k+lambd-1) == lambd*(v+k+lambd-1) and
334340
balanced_incomplete_block_design(v+k+lambd, k+lambd, lambd, existence=True) is True):
@@ -511,7 +517,7 @@ def steiner_triple_system(n):
511517
# apply T and remove duplicates
512518
sts = set(frozenset(T(xx) for xx in x) for x in sts)
513519

514-
return BalancedIncompleteBlockDesign(n, sts, name=name,check=False)
520+
return BIBD(n, sts, name=name,check=False)
515521

516522

517523
def BIBD_from_TD(v,k,existence=False):
@@ -1204,10 +1210,6 @@ def _get_r_s_t_u(v):
12041210
t,u = 30*s+5, 5
12051211
elif x <= 51:
12061212
t,u = 30*s+5, x-25
1207-
elif x <= 66:
1208-
t,u = 30*s+11, x-55
1209-
elif x <= 96:
1210-
t,u = 30*s+11, x-55
12111213
elif x <= 121:
12121214
t,u = 30*s+11, x-55
12131215
elif x <= 146:
@@ -1638,3 +1640,5 @@ def arc(self, s=2, solver=None, verbose=0):
16381640
p.add_constraint(p.sum(b[k] for k in i) <= s)
16391641
p.solve(log=verbose)
16401642
return [self._points[i] for (i,j) in p.get_values(b).items() if j == 1]
1643+
1644+
BIBD = BalancedIncompleteBlockDesign

0 commit comments

Comments
 (0)