Ticket #13192: trac_13192_cleanup.patch

File trac_13192_cleanup.patch, 2.8 KB (added by eisermbi, 9 years ago)
  • sage/graphs/graph.py

    # HG changeset patch
    # User Birk Eisermann <eisermbi@fastmail.fm>
    # Date 1341211294 -28800
    # Node ID a8e07259dfa30ae3924c8750f36b6c2af5da51ff
    # Parent  5f2b67ffd844b6437e6f407bc6e4af2fa8c44982
    trac 13192 code clean up in graph.py
    
    diff --git a/sage/graphs/graph.py b/sage/graphs/graph.py
    a b  
    15731573            edges = self.edges(labels=False)
    15741574            for i in range(len(edges)): # replace edge labels with natural numbers (by index in vertices)
    15751575                edges[i] = (vertices.index(edges[i][0]),vertices.index(edges[i][1]))
    1576             # order edges
    1577             edges.sort(compare_edges)
     1576            # order edges 'reverse lexicographically', that is, for
     1577            # edge (a,b) and edge (c,d) first compare b and d, then a and c;
     1578            edges.sort(key=lambda e: (e[1],e[0]))
    15781579
    15791580            # encode bit vector
    15801581            from math import ceil
     
    50785079        sage: E = G.edges()
    50795080        sage: from sage.graphs.graph import compare_edges
    50805081        sage: compare_edges(E[0], E[2])
     5082        doctest:...: DeprecationWarning: compare_edges(x,y) is deprecated.  Use statement 'cmp(x[1],y[1]) or cmp(x[0],y[0])' instead.
     5083        See http://trac.sagemath.org/13192 for details.
    50815084        -1
    5082         sage: compare_edges(E[0], E[1])
    5083         -1
    5084         sage: compare_edges(E[0], E[0])
    5085         0
    5086         sage: compare_edges(E[1], E[0])
    5087         1
     5085
     5086    TESTS:
     5087
     5088    For the change in method `sparse6_string`, we check that the
     5089    results are still correct. The sorted edges using the new way are
     5090    stored in variable E1 and the sorted edges using the old way are
     5091    stored in variable E2 and both are checked for equivalence::
     5092
     5093        sage: G = graphs.PetersenGraph()
     5094        sage: E1 = G.edges()
     5095        sage: E2 = copy(E1)
     5096        sage: E1.sort(key=lambda e: (e[1],e[0]))
     5097        sage: E2.sort(compare_edges)
     5098        sage: if E1 != E2:
     5099        ...       print "Error: sorting the new way is different from the old way!"
     5100
     5101    Test some random graphs::
     5102
     5103        sage: for k in range(5):
     5104        ...       g = graphs.RandomGNP(25+k,0.3)
     5105        ...       E1 = g.edges()
     5106        ...       E2 = copy(E1)
     5107        ...       E1.sort(key=lambda e: (e[1],e[0]))
     5108        ...       E2.sort(sage.graphs.graph.compare_edges)
     5109        ...       if E1 != E2:
     5110        ...           print "Error: sorting the new way is different from the old way!"
     5111        doctest:...: DeprecationWarning: compare_edges(x,y) is deprecated.  Use statement 'cmp(x[1],y[1]) or cmp(x[0],y[0])' instead.
     5112        See http://trac.sagemath.org/13192 for details.
    50885113    """
     5114    from sage.misc.superseded import deprecation
     5115    deprecation(13192, "compare_edges(x,y) is deprecated.  Use statement 'cmp(x[1],y[1]) or cmp(x[0],y[0])' instead.")
    50895116    if x[1] < y[1]:
    50905117        return -1
    50915118    elif x[1] > y[1]: