Ticket #8927: trac_8927.patch

File trac_8927.patch, 1.4 KB (added by ncohen, 9 years ago)
  • sage/graphs/graph.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1276001333 -7200
    # Node ID b68571f25315cdecf993dde376d095a17f2e02e9
    # Parent  556bb66e4c6dbb92a4ee37c1750d82a5c6298eeb
    trac 8927 -- is_triangle_free
    
    diff -r 556bb66e4c6d -r b68571f25315 sage/graphs/graph.py
    a b  
    13931393        except:
    13941394            return False
    13951395
     1396    def is_triangle_free(self):
     1397        r"""
     1398        Returns whether ``self`` is triangle-free
     1399
     1400        EXAMPLE:
     1401
     1402        The Petersen Graph is triangle-free::
     1403
     1404            sage: g = graphs.PetersenGraph()
     1405            sage: g.is_triangle_free()
     1406            True
     1407
     1408        or a complete Bipartite Graph::
     1409
     1410            sage: g = graphs.CompleteBipartiteGraph(5,6)
     1411            sage: g.is_triangle_free()
     1412            True
     1413
     1414        a tripartite graph, though, contains many triangles ::
     1415
     1416            sage: g = (3 * graphs.CompleteGraph(5)).complement()
     1417            sage: g.is_triangle_free()
     1418            False
     1419        """
     1420
     1421        from sage.graphs.graph_generators import graphs
     1422
     1423        return (self.subgraph_search(graphs.CompleteGraph(3)) is None)
     1424
    13961425    def degree_constrained_subgraph(self, bounds=None, solver=None, verbose=0):
    13971426        r"""
    13981427        Returns a degree-constrained subgraph.