Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

r""" 

Covering designs: coverings of `t`-element subsets of a `v`-set by `k`-sets 

 

A `(v,k,t)` covering design `C` is an incidence structure consisting of a 

set of points `P` of order `v`, and a set of blocks `B`, where each 

block contains `k` points of `P`. Every `t`-element subset of `P` 

must be contained in at least one block. 

 

If every `t`-set is contained in exactly one block of `C`, then we 

have a block design. Following the block design implementation, the 

standard representation of a covering design uses `P = [0,1,..., v-1]`. 

 

In addition to the parameters and incidence structure for a covering 

design from this database, we include extra information: 

 

* Best known lower bound on the size of a `(v,k,t)`-covering design 

* Name of the person(s) who produced the design 

* Method of construction used 

* Date when the design was added to the database 

 

REFERENCES: 

 

.. [1] La Jolla Covering Repository, 

http://www.ccrwest.org/cover.html 

 

.. [2] Coverings, 

Daniel Gordon and Douglas Stinson, 

http://www.ccrwest.org/gordon/hcd.pdf 

from the Handbook of Combinatorial Designs 

 

AUTHORS: 

 

-- Daniel M. Gordon (2008-12-22): initial version 

 

Classes and methods 

------------------- 

""" 

 

#***************************************************************************** 

# Copyright (C) 2008 Daniel M. Gordon <dmgordo@gmail.com> 

# 

# Distributed under the terms of the GNU General Public License (GPL) 

# http://www.gnu.org/licenses/ 

#***************************************************************************** 

from __future__ import print_function 

 

from sage.misc.sage_eval import sage_eval 

from sage.structure.sage_object import SageObject 

from sage.rings.rational import Rational 

from sage.arith.all import binomial 

from sage.combinat.combination import Combinations 

from sage.combinat.designs.incidence_structures import IncidenceStructure 

 

###################### covering design functions ############################## 

 

 

def schonheim(v,k,t): 

r""" 

Schonheim lower bound for size of covering design 

 

INPUT: 

 

- ``v`` -- integer, size of point set 

- ``k`` -- integer, cardinality of each block 

- ``t`` -- integer, cardinality of sets being covered 

 

OUTPUT: 

 

The Schonheim lower bound for such a covering design's size: 

`C(v,k,t) \leq \lceil(\frac{v}{k} \lceil \frac{v-1}{k-1} \cdots \lceil \frac{v-t+1}{k-t+1} \rceil \cdots \rceil \rceil` 

 

EXAMPLES:: 

 

sage: from sage.combinat.designs.covering_design import schonheim 

sage: schonheim(10,3,2) 

17 

sage: schonheim(32,16,8) 

930 

""" 

bound = 1 

for i in range(t-1,-1,-1): 

bound = Rational((bound*(v-i),k-i)).ceil() 

 

return bound 

 

 

def trivial_covering_design(v,k,t): 

r""" 

Construct a trivial covering design. 

 

INPUT: 

 

- ``v`` -- integer, size of point set 

- ``k`` -- integer, cardinality of each block 

- ``t`` -- integer, cardinality of sets being covered 

 

OUTPUT: 

 

`(v,k,t)` covering design 

 

EXAMPLES:: 

 

sage: C = trivial_covering_design(8,3,1) 

sage: print(C) 

C(8,3,1) = 3 

Method: Trivial 

0 1 2 

0 6 7 

3 4 5 

sage: C = trivial_covering_design(5,3,2) 

sage: print(C) 

4 <= C(5,3,2) <= 10 

Method: Trivial 

0 1 2 

0 1 3 

0 1 4 

0 2 3 

0 2 4 

0 3 4 

1 2 3 

1 2 4 

1 3 4 

2 3 4 

 

NOTES: 

 

Cases are: 

 

* `t=0`: This could be empty, but it's a useful convention to have 

one block (which is empty if $k=0$). 

 

* `t=1` : This contains `\lceil v/k \rceil` blocks: 

`[0,...,k-1],[k,...,2k-1],...`. The last block wraps around if 

`k` does not divide `v`. 

 

* anything else: Just use every `k`-subset of `[0,1,...,v-1]`. 

 

""" 

if t==0: #single block [0,...,k-1] 

blk=[] 

for i in range(k): 

blk.append(i) 

return CoveringDesign(v,k,t,1,range(v),[blk],1,"Trivial") 

 

if t==1: #blocks [0,...,k-1],[k,...,2k-1],... 

size = Rational((v,k)).ceil() 

blocks=[] 

for i in range(size-1): 

blk=[] 

for j in range(i*k,(i+1)*k): 

blk.append(j) 

blocks.append(blk) 

 

blk=[] # last block: if k does not divide v, wrap around 

for j in range((size-1)*k,v): 

blk.append(j) 

for j in range(k-len(blk)): 

blk.append(j) 

blk.sort() 

blocks.append(blk) 

return CoveringDesign(v,k,t,size,range(v),blocks,size,"Trivial") 

 

# default case, all k-subsets 

return CoveringDesign(v,k,t,binomial(v,k),range(v),Combinations(range(v),k),schonheim(v,k,t),"Trivial") 

 

 

class CoveringDesign(SageObject): 

""" 

Covering design. 

 

INPUT: 

 

- ``v,k,t`` -- integer parameters of the covering design. 

 

- ``size`` (integer) 

 

- ``points`` -- list of points (default points are `[0,...v-1]`). 

 

- ``blocks`` 

 

- ``low_bd`` (integer) -- lower bound for such a design 

 

- ``method, creator, timestamp`` -- database information. 

""" 

 

def __init__(self, v=0, k=0, t=0, size=0, points=[], blocks=[], low_bd=0, method='', creator ='',timestamp=''): 

""" 

EXAMPLES:: 

 

sage: C=CoveringDesign(5,4,3,4,range(5),[[0,1,2,3],[0,1,2,4],[0,1,3,4],[0,2,3,4]],4, 'Lexicographic Covering') 

sage: print(C) 

C(5,4,3) = 4 

Method: Lexicographic Covering 

0 1 2 3 

0 1 2 4 

0 1 3 4 

0 2 3 4 

""" 

self.__v = v 

self.__k = k 

self.__t = t 

self.__size = size 

if low_bd > 0: 

self.__low_bd = low_bd 

else: 

self.__low_bd = schonheim(v,k,t) 

self.__method = method 

self.__creator = creator 

self.__timestamp = timestamp 

self.__incidence_structure = IncidenceStructure(points, blocks) 

 

 

def __repr__(self): 

""" 

A print method, giving the parameters and any other 

information about the covering (but not the blocks). 

 

EXAMPLES:: 

 

sage: C=CoveringDesign(7,3,2,7,range(7),[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 5]],0, 'Projective Plane') 

sage: C 

(7,3,2)-covering design of size 7 

Lower bound: 7 

Method: Projective Plane 

""" 

repr = '(%d,%d,%d)-covering design of size %d\n' % (self.__v, 

self.__k, 

self.__t, 

self.__size) 

repr += 'Lower bound: %d\n' % (self.__low_bd) 

if self.__creator != '': 

repr += 'Created by: %s\n' % (self.__creator) 

if self.__method != '': 

repr += 'Method: %s\n' % (self.__method) 

if self.__timestamp != '': 

repr += 'Submitted on: %s\n' % (self.__timestamp) 

 

return repr 

 

def __str__(self): 

""" 

A print method, displaying a covering design's parameters and blocks. 

 

OUTPUT: 

 

covering design parameters and blocks, in a readable form 

 

EXAMPLES:: 

 

sage: C=CoveringDesign(7,3,2,7,range(7),[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 5]],0, 'Projective Plane') 

sage: print(C) 

C(7,3,2) = 7 

Method: Projective Plane 

0 1 2 

0 3 4 

0 5 6 

1 3 5 

1 4 6 

2 3 6 

2 4 5 

""" 

if self.__size == self.__low_bd: # check if the covering is known to be optimal 

repr = 'C(%d,%d,%d) = %d\n'%(self.__v,self.__k,self.__t,self.__size) 

else: 

repr = '%d <= C(%d,%d,%d) <= %d\n'%(self.__low_bd,self.__v,self.__k,self.__t,self.__size); 

if self.__creator != '': 

repr += 'Created by: %s\n'%(self.__creator) 

if self.__method != '': 

repr += 'Method: %s\n'%(self.__method) 

if self.__timestamp != '': 

repr += 'Submitted on: %s\n'%(self.__timestamp) 

for i in range(self.__size): 

for j in range(self.__k): 

repr = repr + str(self.__incidence_structure.blocks()[i][j]) + ' ' 

repr += '\n' 

 

return repr 

 

def is_covering(self): 

""" 

Checks that all `t`-sets are in fact covered by the blocks of 

``self`` 

 

.. NOTE:: 

 

This is very slow and wasteful of memory. 

 

EXAMPLES:: 

 

sage: C=CoveringDesign(7,3,2,7,range(7),[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 5]],0, 'Projective Plane') 

sage: C.is_covering() 

True 

sage: C=CoveringDesign(7,3,2,7,range(7),[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 6]],0, 'not a covering') # last block altered 

sage: C.is_covering() 

False 

""" 

v = self.__v 

k = self.__k 

t = self.__t 

Svt = Combinations(range(v),t) 

Skt = Combinations(range(k),t) 

tset = {} # tables of t-sets: False = uncovered, True = covered 

for i in Svt: 

tset[tuple(i)] = False 

 

# mark all t-sets covered by each block 

for a in self.__incidence_structure.blocks(): 

for z in Skt: 

y = [a[x] for x in z] 

tset[tuple(y)] = True 

 

for i in Svt: 

if not tset[tuple(i)]: # uncovered 

return False 

 

return True # everything was covered 

 

def v(self): 

""" 

Return `v`, the number of points in the covering design. 

 

EXAMPLES:: 

 

sage: from sage.combinat.designs.covering_design import CoveringDesign 

sage: C=CoveringDesign(7,3,2,7,range(7),[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 5]],0, 'Projective Plane') 

sage: C.v() 

7 

""" 

return self.__v 

 

 

def k(self): 

""" 

Return `k`, the size of blocks of the covering design 

 

EXAMPLES:: 

 

sage: from sage.combinat.designs.covering_design import CoveringDesign 

sage: C=CoveringDesign(7,3,2,7,range(7),[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 5]],0, 'Projective Plane') 

sage: C.k() 

3 

""" 

return self.__k 

 

 

def t(self): 

""" 

Return `t`, the size of sets which must be covered by the 

blocks of the covering design 

 

EXAMPLES:: 

 

sage: from sage.combinat.designs.covering_design import CoveringDesign 

sage: C=CoveringDesign(7,3,2,7,range(7),[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 5]],0, 'Projective Plane') 

sage: C.t() 

2 

""" 

return self.__t 

 

def size(self): 

""" 

Return the number of blocks in the covering design 

 

EXAMPLES:: 

 

sage: from sage.combinat.designs.covering_design import CoveringDesign 

sage: C=CoveringDesign(7,3,2,7,range(7),[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 5]],0, 'Projective Plane') 

sage: C.size() 

7 

""" 

return self.__size 

 

 

def low_bd(self): 

""" 

Return a lower bound for the number of blocks a covering 

design with these parameters could have. 

 

Typically this is the Schonheim bound, but for some parameters 

better bounds have been shown. 

 

EXAMPLES:: 

 

sage: from sage.combinat.designs.covering_design import CoveringDesign 

sage: C=CoveringDesign(7,3,2,7,range(7),[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 5]],0, 'Projective Plane') 

sage: C.low_bd() 

7 

""" 

return self.__low_bd 

 

def method(self): 

""" 

Return the method used to create the covering design 

This field is optional, and is used in a database to give information about how coverings were constructed 

 

EXAMPLES:: 

 

sage: from sage.combinat.designs.covering_design import CoveringDesign 

sage: C=CoveringDesign(7,3,2,7,range(7),[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 5]],0, 'Projective Plane') 

sage: C.method() 

'Projective Plane' 

""" 

return self.__method 

 

def creator(self): 

""" 

Return the creator of the covering design 

 

This field is optional, and is used in a database to give 

attribution for the covering design It can refer to the person 

who submitted it, or who originally gave a construction 

 

EXAMPLES:: 

 

sage: from sage.combinat.designs.covering_design import CoveringDesign 

sage: C=CoveringDesign(7,3,2,7,range(7),[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 5]],0, 'Projective Plane','Gino Fano') 

sage: C.creator() 

'Gino Fano' 

""" 

return self.__creator 

 

def timestamp(self): 

""" 

Return the time that the covering was submitted to the database 

 

EXAMPLES:: 

 

sage: from sage.combinat.designs.covering_design import CoveringDesign 

sage: C=CoveringDesign(7,3,2,7,range(7),[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 5]],0, 'Projective Plane','Gino Fano','1892-01-01 00:00:00') 

sage: C.timestamp() #Fano had an article in 1892, I don't know the date it appeared 

'1892-01-01 00:00:00' 

""" 

return self.__timestamp 

 

 

def incidence_structure(self): 

""" 

Return the incidence structure of a covering design, without all the extra parameters. 

 

EXAMPLES:: 

 

sage: from sage.combinat.designs.covering_design import CoveringDesign 

sage: C=CoveringDesign(7,3,2,7,range(7),[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 5]],0, 'Projective Plane') 

sage: D = C.incidence_structure() 

sage: D.ground_set() 

[0, 1, 2, 3, 4, 5, 6] 

sage: D.blocks() 

[[0, 1, 2], [0, 3, 4], [0, 5, 6], [1, 3, 5], [1, 4, 6], [2, 3, 6], [2, 4, 5]] 

 

""" 

return self.__incidence_structure 

 

def best_known_covering_design_www(v, k, t, verbose=False): 

r""" 

Gives the best known `(v,k,t)` covering design, using the database 

available at `<http://www.ccrwest.org/>`_ 

 

INPUT: 

 

- ``v`` -- integer, the size of the point set for the design 

- ``k`` -- integer, the number of points per block 

- ``t`` -- integer, the size of sets covered by the blocks 

- ``verbose`` -- bool (default=``False``), print verbose message 

 

OUTPUT: 

 

A :class:`CoveringDesign` object representing the ``(v,k,t)``-covering 

design with smallest number of blocks available in the database. 

 

EXAMPLES:: 

 

sage: from sage.combinat.designs.covering_design import best_known_covering_design_www 

sage: C = best_known_covering_design_www(7, 3, 2) # optional - internet 

sage: print(C) # optional - internet 

C(7,3,2) = 7 

Method: lex covering 

Submitted on: 1996-12-01 00:00:00 

0 1 2 

0 3 4 

0 5 6 

1 3 5 

1 4 6 

2 3 6 

2 4 5 

 

This function raises a ValueError if the ``(v,k,t)`` parameters are not 

found in the database. 

""" 

# import compatible with py2 and py3 

from six.moves.urllib.request import urlopen 

 

from sage.misc.sage_eval import sage_eval 

 

v = int(v) 

k = int(k) 

t = int(t) 

 

param = ("?v=%s&k=%s&t=%s"%(v,k,t)) 

 

url = "http://www.ccrwest.org/cover/get_cover.php"+param 

if verbose: 

print("Looking up the bounds at %s" % url) 

f = urlopen(url) 

s = f.read() 

f.close() 

 

if 'covering not in database' in s: #not found 

str = "no (%d,%d,%d) covering design in database\n"%(v,k,t) 

raise ValueError(str) 

 

return sage_eval(s)