Ticket #8781: trac_8781.patch

File trac_8781.patch, 3.2 KB (added by ncohen, 9 years ago)
  • sage/graphs/generic_graph.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1272370432 -7200
    # Node ID 3ffb58d8c602e90a7f446f31d1544128878190ad
    # Parent  ef74a6ed21179df343f658c015d7b068bb28c0f3
    trac #8781 : is_overfull and update to edge_coloring
    
    diff -r ef74a6ed2117 -r 3ffb58d8c602 sage/graphs/generic_graph.py
    a b  
    17831783                return False
    17841784        return True
    17851785
     1786    def is_overfull(self):
     1787        r"""
     1788        Tests whether the current graph is overfull.
     1789
     1790        A graph `G` on `n` vertices and `m` edges is said to
     1791        be overfull if :
     1792
     1793            - `n` is odd
     1794
     1795            - It satisfies `2m > (n-1)\Delta(G)`, where
     1796              `\Delta(G)` denotes the maximal degree of
     1797              a vertex in `G`
     1798
     1799        An overfull graph must have a chromatic index of `\Delta(G)+1`.
     1800
     1801        EXAMPLE:
     1802
     1803        A complete graph is overfull if and only if its number
     1804        of vertices is odd::
     1805
     1806            sage: graphs.CompleteGraph(6).is_overfull()
     1807            False
     1808            sage: graphs.CompleteGraph(7).is_overfull()
     1809            True
     1810
     1811        The Petersen Graph, though, is not overfull while
     1812        its chromatic index is `\Delta+1`::
     1813
     1814            sage: g = graphs.PetersenGraph()
     1815            sage: g.is_overfull()
     1816            False
     1817            sage: from sage.graphs.graph_coloring import edge_coloring
     1818            sage: max(g.degree()) + 1 ==  edge_coloring(g, value_only=True) # optional - requires GLPK CBC or CPLEX
     1819            True
     1820        """
     1821
     1822        return (self.order() % 2 == 1) and \
     1823            (2*self.size() > max(self.degree())*(self.order()-1))
     1824
    17861825    def order(self):
    17871826        """
    17881827        Returns the number of vertices. Note that len(G) returns the number
  • sage/graphs/graph_coloring.py

    diff -r ef74a6ed2117 -r 3ffb58d8c602 sage/graphs/graph_coloring.py
    a b  
    506506      graph, and this is not the easiest way. By Vizing's theorem, a graph
    507507      has a chromatic index equal to `\Delta` or to `\Delta + 1`.
    508508
     509    .. NOTE::
     510
     511       In a few cases, it is possible to find very quickly the chromatic
     512       index of a graph, while it remains a tedious job to compute
     513       a corresponding coloring. For this reason, ``value_only = True``
     514       can sometimes be much faster, and it is a bad idea to compute
     515       the whole coloring if you do not need it !
     516
    509517    EXAMPLE::
    510518
    511519       sage: from sage.graphs.graph_coloring import edge_coloring
     
    525533
    526534    if g.is_clique():
    527535        if value_only:
    528             return g.order() if g.order() % 2 == 0 else g.order() + 1
     536            return g.order()-1 if g.order() % 2 == 0 else g.order()
    529537        vertices = g.vertices()
    530538        r = round_robin(g.order())
    531539        classes = [[] for v in g]
     
    538546        else:
    539547            return classes
    540548
     549    if value_only and g.is_overfull():
     550        return max(g.degree())+1
     551
    541552    p = MixedIntegerLinearProgram(maximization=True)
    542553    color = p.new_variable(dim=2)
    543554    obj = {}