Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
trac #16553: Clean IncidenceStructure
Browse files Browse the repository at this point in the history
  • Loading branch information
videlec authored and nathanncohen committed Jun 27, 2014
1 parent 16a0c5d commit ff72248
Show file tree
Hide file tree
Showing 7 changed files with 700 additions and 620 deletions.
3 changes: 1 addition & 2 deletions src/sage/combinat/designs/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
["ProjectiveGeometryDesign",
"AffineGeometryDesign",
"WittDesign",
"HadamardDesign",
"BlockDesign_generic"],
"HadamardDesign"],
("This method soon will not be available in that "
"way anymore. To use it, you can now call it by "
"typing designs.%(name)s"))
Expand Down
80 changes: 41 additions & 39 deletions src/sage/combinat/designs/bibd.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
sage: designs.balanced_incomplete_block_design(7,3)
Incidence structure with 7 points and 7 blocks
sage: designs.balanced_incomplete_block_design(7,3).blocks()
[[0, 1, 3], [0, 2, 4], [0, 5, 6], [1, 2, 6], [1, 4, 5], [2, 3, 5], [3, 4, 6]]
((0, 1, 3), (0, 2, 4), (0, 5, 6), (1, 2, 6), (1, 4, 5), (2, 3, 5), (3, 4, 6))
sage: designs.balanced_incomplete_block_design(13,4).blocks()
[[0, 1, 2, 12], [0, 3, 6, 9], [0, 4, 8, 10], [0, 5, 7, 11], [1, 3, 8, 11],
[1, 4, 7, 9], [1, 5, 6, 10], [2, 3, 7, 10], [2, 4, 6, 11], [2, 5, 8, 9],
[3, 4, 5, 12], [6, 7, 8, 12], [9, 10, 11, 12]]
((0, 1, 2, 12), (0, 3, 6, 9), (0, 4, 8, 10), (0, 5, 7, 11), (1, 3, 8, 11),
(1, 4, 7, 9), (1, 5, 6, 10), (2, 3, 7, 10), (2, 4, 6, 11), (2, 5, 8, 9),
(3, 4, 5, 12), (6, 7, 8, 12), (9, 10, 11, 12))
`K_4`-decompositions of `K_v`
-----------------------------
Expand Down Expand Up @@ -99,18 +99,18 @@ def balanced_incomplete_block_design(v,k,existence=False,use_LJCR=False):
EXAMPLES::
sage: designs.balanced_incomplete_block_design(7,3).blocks()
[[0, 1, 3], [0, 2, 4], [0, 5, 6], [1, 2, 6], [1, 4, 5], [2, 3, 5], [3, 4, 6]]
((0, 1, 3), (0, 2, 4), (0, 5, 6), (1, 2, 6), (1, 4, 5), (2, 3, 5), (3, 4, 6))
sage: B = designs.balanced_incomplete_block_design(21,5, use_LJCR=True) # optional - internet
sage: B # optional - internet
Incidence structure with 21 points and 21 blocks
sage: B.blocks() # optional - internet
[[0, 1, 2, 3, 20], [0, 4, 8, 12, 16], [0, 5, 10, 15, 19],
[0, 6, 11, 13, 17], [0, 7, 9, 14, 18], [1, 4, 11, 14, 19],
[1, 5, 9, 13, 16], [1, 6, 8, 15, 18], [1, 7, 10, 12, 17],
[2, 4, 9, 15, 17], [2, 5, 11, 12, 18], [2, 6, 10, 14, 16],
[2, 7, 8, 13, 19], [3, 4, 10, 13, 18], [3, 5, 8, 14, 17],
[3, 6, 9, 12, 19], [3, 7, 11, 15, 16], [4, 5, 6, 7, 20],
[8, 9, 10, 11, 20], [12, 13, 14, 15, 20], [16, 17, 18, 19, 20]]
((0, 1, 2, 3, 20), (0, 4, 8, 12, 16), (0, 5, 10, 15, 19),
(0, 6, 11, 13, 17), (0, 7, 9, 14, 18), (1, 4, 11, 14, 19),
(1, 5, 9, 13, 16), (1, 6, 8, 15, 18), (1, 7, 10, 12, 17),
(2, 4, 9, 15, 17), (2, 5, 11, 12, 18), (2, 6, 10, 14, 16),
(2, 7, 8, 13, 19), (3, 4, 10, 13, 18), (3, 5, 8, 14, 17),
(3, 6, 9, 12, 19), (3, 7, 11, 15, 16), (4, 5, 6, 7, 20),
(8, 9, 10, 11, 20), (12, 13, 14, 15, 20), (16, 17, 18, 19, 20))
sage: designs.balanced_incomplete_block_design(20,5, use_LJCR=True) # optional - internet
Traceback (most recent call last):
...
Expand Down Expand Up @@ -156,12 +156,12 @@ def balanced_incomplete_block_design(v,k,existence=False,use_LJCR=False):
if v == 1:
if existence:
return True
return BlockDesign(v, [], test=False)
return BlockDesign(v, [], check=False)

if k == v:
if existence:
return True
return BlockDesign(v, [range(v)], test=False)
return BlockDesign(v, [range(v)], check=False)

if v < k or k < 2 or (v-1) % (k-1) != 0 or (v*(v-1)) % (k*(k-1)) != 0:
if existence:
Expand All @@ -172,26 +172,26 @@ def balanced_incomplete_block_design(v,k,existence=False,use_LJCR=False):
if existence:
return True
from itertools import combinations
return BlockDesign(v, combinations(range(v),2), test = False)
return BlockDesign(v, combinations(range(v),2), check=False)
if k == 3:
if existence:
return v%6 == 1 or v%6 == 3
return steiner_triple_system(v)
if k == 4:
if existence:
return v%12 == 1 or v%12 == 4
return BlockDesign(v, v_4_1_BIBD(v), test = False)
return BlockDesign(v, v_4_1_BIBD(v), check=False)
if k == 5:
if existence:
return v%20 == 1 or v%20 == 5
return BlockDesign(v, v_5_1_BIBD(v), test = False)
return BlockDesign(v, v_5_1_BIBD(v), check=False)

from difference_family import difference_family

if BIBD_from_TD(v,k,existence=True):
if existence:
return True
return BlockDesign(v, BIBD_from_TD(v,k))
return BlockDesign(v, BIBD_from_TD(v,k), check=False)
if v == (k-1)**2+k and is_prime_power(k-1):
if existence:
return True
Expand All @@ -201,7 +201,7 @@ def balanced_incomplete_block_design(v,k,existence=False,use_LJCR=False):
if existence:
return True
G,D = difference_family(v,k)
return BlockDesign(v, BIBD_from_difference_family(G,D,check=False), test=False)
return BlockDesign(v, BIBD_from_difference_family(G,D,check=False), check=False)
if use_LJCR:
from covering_design import best_known_covering_design_www
B = best_known_covering_design_www(v,k,2)
Expand All @@ -213,7 +213,7 @@ def balanced_incomplete_block_design(v,k,existence=False,use_LJCR=False):
return False
raise EmptySetError("No such design exists !")
B = B.incidence_structure()
if len(B.blcks) == expected_n_of_blocks:
if B.num_blocks() == expected_n_of_blocks:
if existence:
return True
else:
Expand Down Expand Up @@ -253,12 +253,14 @@ def steiner_triple_system(n):
sage: sts
Incidence structure with 9 points and 12 blocks
sage: list(sts)
[[0, 1, 5], [0, 2, 4], [0, 3, 6], [0, 7, 8], [1, 2, 3], [1, 4, 7], [1, 6, 8], [2, 5, 8], [2, 6, 7], [3, 4, 8], [3, 5, 7], [4, 5, 6]]
[(0, 1, 5), (0, 2, 4), (0, 3, 6), (0, 7, 8), (1, 2, 3),
(1, 4, 7), (1, 6, 8), (2, 5, 8), (2, 6, 7), (3, 4, 8),
(3, 5, 7), (4, 5, 6)]
As any pair of vertices is covered once, its parameters are ::
sage: sts.parameters(t=2)
(2, 9, 3, 1)
sage: sts.is_t_design(return_parameters=True)
(True, (2, 9, 3, 1))
An exception is raised for invalid values of ``n`` ::
Expand Down Expand Up @@ -359,21 +361,21 @@ def BIBD_from_TD(v,k,existence=False):
sage: from sage.combinat.designs.bibd import BIBD_from_TD
sage: BIBD_from_TD(25,5,existence=True)
True
sage: _ = BlockDesign(25,BIBD_from_TD(25,5))
sage: _ = designs.BlockDesign(25,BIBD_from_TD(25,5))
Second construction::
sage: from sage.combinat.designs.bibd import BIBD_from_TD
sage: BIBD_from_TD(21,5,existence=True)
True
sage: _ = BlockDesign(21,BIBD_from_TD(21,5))
sage: _ = designs.BlockDesign(21,BIBD_from_TD(21,5))
Third construction::
sage: from sage.combinat.designs.bibd import BIBD_from_TD
sage: BIBD_from_TD(85,5,existence=True)
True
sage: _ = BlockDesign(85,BIBD_from_TD(85,5))
sage: _ = designs.BlockDesign(85,BIBD_from_TD(85,5))
No idea::
Expand Down Expand Up @@ -638,7 +640,7 @@ def BIBD_from_PBD(PBD,v,k,check=True,base_cases={}):
n = len(X)
N = (k-1)*n+1
if not (n,k) in base_cases:
base_cases[n,k] = _relabel_bibd(balanced_incomplete_block_design(N,k).blcks,N)
base_cases[n,k] = _relabel_bibd(balanced_incomplete_block_design(N,k), N)

for XX in base_cases[n,k]:
if N-1 in XX:
Expand Down Expand Up @@ -671,9 +673,9 @@ def _check_pbd(B,v,S):
EXAMPLE::
sage: designs.balanced_incomplete_block_design(40,4).blocks() # indirect doctest
[[0, 1, 2, 12], [0, 3, 6, 9], [0, 4, 8, 10],
[0, 5, 7, 11], [0, 13, 26, 39], [0, 14, 25, 28],
[0, 15, 27, 38], [0, 16, 22, 32], [0, 17, 23, 34],
((0, 1, 2, 12), (0, 3, 6, 9), (0, 4, 8, 10),
(0, 5, 7, 11), (0, 13, 26, 39), (0, 14, 25, 28),
(0, 15, 27, 38), (0, 16, 22, 32), (0, 17, 23, 34),
...
sage: from sage.combinat.designs.bibd import _check_pbd
sage: _check_pbd([[1],[]],1,[1,0])
Expand Down Expand Up @@ -757,9 +759,9 @@ def _relabel_bibd(B,n,p=None):
EXAMPLE::
sage: designs.balanced_incomplete_block_design(40,4).blocks() # indirect doctest
[[0, 1, 2, 12], [0, 3, 6, 9], [0, 4, 8, 10],
[0, 5, 7, 11], [0, 13, 26, 39], [0, 14, 25, 28],
[0, 15, 27, 38], [0, 16, 22, 32], [0, 17, 23, 34],
((0, 1, 2, 12), (0, 3, 6, 9), (0, 4, 8, 10),
(0, 5, 7, 11), (0, 13, 26, 39), (0, 14, 25, 28),
(0, 15, 27, 38), (0, 16, 22, 32), (0, 17, 23, 34),
...
"""
if p is None:
Expand Down Expand Up @@ -798,9 +800,9 @@ def PBD_4_5_8_9_12(v, check=True):
EXAMPLES::
sage: designs.balanced_incomplete_block_design(40,4).blocks() # indirect doctest
[[0, 1, 2, 12], [0, 3, 6, 9], [0, 4, 8, 10],
[0, 5, 7, 11], [0, 13, 26, 39], [0, 14, 25, 28],
[0, 15, 27, 38], [0, 16, 22, 32], [0, 17, 23, 34],
((0, 1, 2, 12), (0, 3, 6, 9), (0, 4, 8, 10),
(0, 5, 7, 11), (0, 13, 26, 39), (0, 14, 25, 28),
(0, 15, 27, 38), (0, 16, 22, 32), (0, 17, 23, 34),
...
Check that :trac:`16476` is fixed::
Expand Down Expand Up @@ -877,9 +879,9 @@ def _PBD_4_5_8_9_12_closure(B):
EXAMPLES::
sage: designs.balanced_incomplete_block_design(40,4).blocks() # indirect doctest
[[0, 1, 2, 12], [0, 3, 6, 9], [0, 4, 8, 10],
[0, 5, 7, 11], [0, 13, 26, 39], [0, 14, 25, 28],
[0, 15, 27, 38], [0, 16, 22, 32], [0, 17, 23, 34],
((0, 1, 2, 12), (0, 3, 6, 9), (0, 4, 8, 10),
(0, 5, 7, 11), (0, 13, 26, 39), (0, 14, 25, 28),
(0, 15, 27, 38), (0, 16, 22, 32), (0, 17, 23, 34),
...
"""
BB = []
Expand Down
Loading

0 comments on commit ff72248

Please sign in to comment.