| 1303 | def is_even_hole_free(self, certificate = False): |
| 1304 | r""" |
| 1305 | Tests whether ``self`` contains an induced even hole. |
| 1306 | |
| 1307 | A Hole is a cycle of length at least 4 (included). It is said |
| 1308 | to be even (resp. odd) if its length is even (resp. odd). |
| 1309 | |
| 1310 | Even-hole-free graphs always contain a bisimplicial vertex, |
| 1311 | which ensures that their chromatic number is at most twice |
| 1312 | their clique number [ABCHRS08]_. |
| 1313 | |
| 1314 | INPUT: |
| 1315 | |
| 1316 | - ``certificate`` (boolean) -- When ``certificate = False``, |
| 1317 | this method only returns ``True`` or ``False``. If |
| 1318 | ``certificate = True``, the subgraph found is returned |
| 1319 | instead of ``False``. |
| 1320 | |
| 1321 | EXAMPLE: |
| 1322 | |
| 1323 | Is the Petersen Graph even-hole-free :: |
| 1324 | |
| 1325 | sage: g = graphs.PetersenGraph() |
| 1326 | sage: g.is_even_hole_free() |
| 1327 | False |
| 1328 | |
| 1329 | As any chordal graph is hole-free, interval graphs behave the |
| 1330 | same way:: |
| 1331 | |
| 1332 | sage: g = graphs.RandomInterval(20) |
| 1333 | sage: g.is_even_hole_free() |
| 1334 | True |
| 1335 | |
| 1336 | It is clear, though, that a random Bipartite Graph which is |
| 1337 | not a forest has an even hole:: |
| 1338 | |
| 1339 | sage: g = graphs.RandomBipartite(10, 10, .5) |
| 1340 | sage: g.is_even_hole_free() |
| 1341 | False |
| 1342 | |
| 1343 | We can check the certificate returned is indeed an even |
| 1344 | cycle:: |
| 1345 | |
| 1346 | sage: cycle = g.is_even_hole_free(certificate = True) |
| 1347 | sage: cycle.order() % 2 == 0 |
| 1348 | True |
| 1349 | sage: cycle.is_isomorphic(graphs.CycleGraph(cycle.order())) |
| 1350 | True |
| 1351 | |
| 1352 | REFERENCE: |
| 1353 | |
| 1354 | .. [ABCHRS08] L. Addario-Berry, M. Chudnovsky, F. Havet, B. Reed, P. Seymour |
| 1355 | Bisimplicial vertices in even-hole-free graphs |
| 1356 | Journal of Combinatorial Theory, Series B |
| 1357 | vol 98, n.6 pp 1119-1164, 2008 |
| 1358 | """ |
| 1359 | from sage.graphs.graph_generators import GraphGenerators |
| 1360 | |
| 1361 | girth = self.girth() |
| 1362 | |
| 1363 | if girth > self.order(): |
| 1364 | start = 4 |
| 1365 | |
| 1366 | elif girth % 2 == 0: |
| 1367 | if not certificate: |
| 1368 | return False |
| 1369 | start = girth |
| 1370 | |
| 1371 | else: |
| 1372 | start = girth + 1 |
| 1373 | |
| 1374 | while start <= self.order(): |
| 1375 | |
| 1376 | |
| 1377 | subgraph = self.subgraph_search(GraphGenerators().CycleGraph(start), induced = True) |
| 1378 | |
| 1379 | if not subgraph is None: |
| 1380 | if certificate: |
| 1381 | return subgraph |
| 1382 | else: |
| 1383 | return False |
| 1384 | |
| 1385 | start = start + 2 |
| 1386 | |
| 1387 | return True |
| 1388 | |
| 1389 | def is_odd_hole_free(self, certificate = False): |
| 1390 | r""" |
| 1391 | Tests whether ``self`` contains an induced odd hole. |
| 1392 | |
| 1393 | A Hole is a cycle of length at least 4 (included). It is said |
| 1394 | to be even (resp. odd) if its length is even (resp. odd). |
| 1395 | |
| 1396 | It is interesting to notice that while it is polynomial to |
| 1397 | check whether a graph has an odd hole or an odd antihole [CRST06]_, it is |
| 1398 | not known whether testing for one of these two cases |
| 1399 | independently is polynomial too. |
| 1400 | |
| 1401 | INPUT: |
| 1402 | |
| 1403 | - ``certificate`` (boolean) -- When ``certificate = False``, |
| 1404 | this method only returns ``True`` or ``False``. If |
| 1405 | ``certificate = True``, the subgraph found is returned |
| 1406 | instead of ``False``. |
| 1407 | |
| 1408 | EXAMPLE: |
| 1409 | |
| 1410 | Is the Petersen Graph odd-hole-free :: |
| 1411 | |
| 1412 | sage: g = graphs.PetersenGraph() |
| 1413 | sage: g.is_odd_hole_free() |
| 1414 | False |
| 1415 | |
| 1416 | Which was to be expected, as its girth is 5 :: |
| 1417 | |
| 1418 | sage: g.girth() |
| 1419 | 5 |
| 1420 | |
| 1421 | We can check the certificate returned is indeed a 5-cycle:: |
| 1422 | |
| 1423 | sage: cycle = g.is_odd_hole_free(certificate = True) |
| 1424 | sage: cycle.is_isomorphic(graphs.CycleGraph(5)) |
| 1425 | True |
| 1426 | |
| 1427 | As any chordal graph is hole-free, no interval graph has an odd hole:: |
| 1428 | |
| 1429 | sage: g = graphs.RandomInterval(20) |
| 1430 | sage: g.is_odd_hole_free() |
| 1431 | True |
| 1432 | |
| 1433 | REFERENCES: |
| 1434 | |
| 1435 | .. [CRST06] M. Chudnovsky, G. Cornuejols, X. Liu, P. Seymour, K. Vuskovic |
| 1436 | Recognizing berge graphs |
| 1437 | Combinatorica vol 25, n 2, pages 143--186 |
| 1438 | 2005 |
| 1439 | """ |
| 1440 | from sage.graphs.graph_generators import GraphGenerators |
| 1441 | |
| 1442 | girth = self.girth() |
| 1443 | |
| 1444 | if girth > self.order() or girth == 3: |
| 1445 | start = 5 |
| 1446 | |
| 1447 | elif girth % 2 == 1: |
| 1448 | if not certificate: |
| 1449 | return False |
| 1450 | start = girth |
| 1451 | |
| 1452 | else: |
| 1453 | start = girth + 1 |
| 1454 | |
| 1455 | while start <= self.order(): |
| 1456 | |
| 1457 | subgraph = self.subgraph_search(GraphGenerators().CycleGraph(start), induced = True) |
| 1458 | |
| 1459 | if not subgraph is None: |
| 1460 | if certificate: |
| 1461 | return subgraph |
| 1462 | else: |
| 1463 | return False |
| 1464 | |
| 1465 | start = start + 2 |
| 1466 | |
| 1467 | return True |
| 1468 | |