Ticket #9195: trac_9195.patch

File trac_9195.patch, 2.8 KB (added by ncohen, 11 years ago)
  • sage/graphs/graph.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1276085553 -7200
    # Node ID f2a4ecd3ead0342afa15ef924f69c884b10c68fd
    # Parent  556bb66e4c6dbb92a4ee37c1750d82a5c6298eeb
    trac 9195 -- Split graph recognition
    
    diff -r 556bb66e4c6d -r f2a4ecd3ead0 sage/graphs/graph.py
    a b  
    13931393        except:
    13941394            return False
    13951395
     1396    def is_split(self):
     1397        r"""
     1398        Returns ``True`` if the graph is a Split graph, ``False`` otherwise.
     1399
     1400        A Graph `G` is said to be a split graph if its vertices `V(G)`
     1401        can be partitioned into two sets `K` and `I` such that the
     1402        vertices of `K` induce a complete graphe, and those of `I` are
     1403        an independent set.
     1404
     1405        There is a simple test to check whether a graph is a split
     1406        graph (see, for instance, the book "Graph Classes, a survey"
     1407        [GraphClasses]_ page 203) :
     1408
     1409        Given the degree sequence `d_1 \geq ... \geq d_n` of `G`, a graph
     1410        is a split graph if and only if :
     1411
     1412        .. MATH::
     1413       
     1414            \sum_{i=1}^\omega d_i = \omega (\omega - 1) + \sum_{i=\omega + 1}^nd_i
     1415
     1416        where `\omega = max \{i:d_i\geq i-1\}`.
     1417
     1418
     1419        EXAMPLES:
     1420
     1421        Split graphs are, in particular, chordal graphs. Hence, The Petersen graph
     1422        can not be split::
     1423
     1424            sage: graphs.PetersenGraph().is_split()
     1425            False
     1426
     1427        We can easily build some "random" split graph by creating a
     1428        complete graph, and adding vertices only connected
     1429        to some random vertices of the clique::
     1430
     1431            sage: g = graphs.CompleteGraph(10)
     1432            sage: sets = Subsets(Set(range(10)))
     1433            sage: for i in range(10, 25):
     1434            ...      g.add_edges([(i,k) for k in sets.random_element()])
     1435            sage: g.is_split()
     1436            True
     1437
     1438        REFERENCES:
     1439
     1440        .. [GraphClasses] A. Brandstadt, VB Le and JP Spinrad
     1441          Graph classes: a survey
     1442          SIAM Monographs on Discrete Mathematics and Applications},
     1443          1999
     1444        """
     1445       
     1446        # our degree sequence is numbered from 0 to n-1, so to avoid
     1447        # any mistake, let's fix it :-)
     1448        degree_sequence = [0] + sorted(self.degree(), reverse = True)
     1449
     1450        for (i, d) in enumerate(degree_sequence):
     1451            if d >= i - 1:
     1452                omega = i
     1453            else:
     1454                break
     1455
     1456        left = sum(degree_sequence[:omega + 1])
     1457        right = omega * (omega - 1) + sum(degree_sequence[omega + 1:])
     1458
     1459        return left == right
     1460
     1461
    13961462    def degree_constrained_subgraph(self, bounds=None, solver=None, verbose=0):
    13971463        r"""
    13981464        Returns a degree-constrained subgraph.