Ticket #8781: trac_8781-reviewer.patch

File trac_8781-reviewer.patch, 4.3 KB (added by mvngu, 10 years ago)
  • sage/graphs/generic_graph.py

    # HG changeset patch
    # User Minh Van Nguyen <nguyenminh2@gmail.com>
    # Date 1273476129 25200
    # Node ID d5031af3fbfe17a236c48dc3de4d97fb8fd01d4d
    # Parent  170b464744ec203ea1c8498d844a99491807c609
    #8781: reviewer patch: overfull graph (and a bug in edge_coloring)
    
    diff --git a/sage/graphs/generic_graph.py b/sage/graphs/generic_graph.py
    a b  
    18141814        Tests whether the current graph is overfull.
    18151815
    18161816        A graph `G` on `n` vertices and `m` edges is said to
    1817         be overfull if :
    1818 
    1819             - `n` is odd
    1820 
    1821             - It satisfies `2m > (n-1)\Delta(G)`, where
    1822               `\Delta(G)` denotes the maximal degree of
    1823               a vertex in `G`
     1817        be overfull if:
     1818
     1819        - `n` is odd
     1820
     1821        - It satisfies `2m > (n-1)\Delta(G)`, where
     1822          `\Delta(G)` denotes the maximum degree
     1823          among all vertices in `G`.
    18241824
    18251825        An overfull graph must have a chromatic index of `\Delta(G)+1`.
    18261826
    1827         EXAMPLE:
    1828 
    1829         A complete graph is overfull if and only if its number
    1830         of vertices is odd::
     1827        EXAMPLES:
     1828
     1829        A complete graph of order `n > 1` is overfull if and only if `n` is
     1830        odd::
    18311831
    18321832            sage: graphs.CompleteGraph(6).is_overfull()
    18331833            False
    18341834            sage: graphs.CompleteGraph(7).is_overfull()
    18351835            True
     1836            sage: graphs.CompleteGraph(1).is_overfull()
     1837            False
     1838
     1839        The claw graph is not overfull::
     1840
     1841            sage: from sage.graphs.graph_coloring import edge_coloring
     1842            sage: g = graphs.ClawGraph()
     1843            sage: g
     1844            Claw graph: Graph on 4 vertices
     1845            sage: edge_coloring(g, value_only=True)  # optional - requires GLPK, CBC, or CPLEX
     1846            3
     1847            sage: g.is_overfull()
     1848            False
     1849
     1850        Checking that all complete graphs `K_n` for even `0 \leq n \leq 100`
     1851        are not overfull::
     1852
     1853            sage: def check_overfull_Kn_even(n):
     1854            ...       i = 0
     1855            ...       while i <= n:
     1856            ...           if graphs.CompleteGraph(i).is_overfull():
     1857            ...               print "A complete graph of even order cannot be overfull."
     1858            ...               return
     1859            ...           i += 2
     1860            ...       print "Complete graphs of even order up to %s are not overfull." % n
     1861            ...
     1862            sage: check_overfull_Kn_even(100)  # long time
     1863            Complete graphs of even order up to 100 are not overfull.
     1864
     1865        The null graph, i.e. the graph with no vertices, is not overfull::
     1866
     1867            sage: Graph().is_overfull()
     1868            False
     1869            sage: graphs.CompleteGraph(0).is_overfull()
     1870            False
     1871
     1872        Checking that all complete graphs `K_n` for odd `1 < n \leq 100`
     1873        are overfull::
     1874
     1875            sage: def check_overfull_Kn_odd(n):
     1876            ...       i = 3
     1877            ...       while i <= n:
     1878            ...           if not graphs.CompleteGraph(i).is_overfull():
     1879            ...               print "A complete graph of odd order > 1 must be overfull."
     1880            ...               return
     1881            ...           i += 2
     1882            ...       print "Complete graphs of odd order > 1 up to %s are overfull." % n
     1883            ...
     1884            sage: check_overfull_Kn_odd(100)  # long time
     1885            Complete graphs of odd order > 1 up to 100 are overfull.
    18361886
    18371887        The Petersen Graph, though, is not overfull while
    18381888        its chromatic index is `\Delta+1`::
     
    18441894            sage: max(g.degree()) + 1 ==  edge_coloring(g, value_only=True) # optional - requires GLPK CBC or CPLEX
    18451895            True
    18461896        """
    1847 
    1848         return (self.order() % 2 == 1) and \
    1849             (2*self.size() > max(self.degree())*(self.order()-1))
     1897        # # A possible optimized version. But the gain in speed is very little.
     1898        # return bool(self._backend.num_verts() & 1) and (  # odd order n
     1899        #     2 * self._backend.num_edges(self._directed) > #2m > \Delta(G)*(n-1)
     1900        #     max(self.degree()) * (self._backend.num_verts() - 1))
     1901        # unoptimized version
     1902        return (self.order() % 2 == 1) and (
     1903            2 * self.size() > max(self.degree()) * (self.order() - 1))
    18501904
    18511905    def order(self):
    18521906        """