# 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 edges = self.edges(labels=False) for i in range(len(edges)): # replace edge labels with natural numbers (by index in vertices) edges[i] = (vertices.index(edges[i][0]),vertices.index(edges[i][1])) # order edges edges.sort(compare_edges) # order edges 'reverse lexicographically', that is, for # edge (a,b) and edge (c,d) first compare b and d, then a and c; edges.sort(key=lambda e: (e[1],e[0])) # encode bit vector from math import ceil sage: E = G.edges() sage: from sage.graphs.graph import compare_edges sage: compare_edges(E[0], E[2]) doctest:...: DeprecationWarning: compare_edges(x,y) is deprecated.  Use statement 'cmp(x[1],y[1]) or cmp(x[0],y[0])' instead. See http://trac.sagemath.org/13192 for details. -1 sage: compare_edges(E[0], E[1]) -1 sage: compare_edges(E[0], E[0]) 0 sage: compare_edges(E[1], E[0]) 1 TESTS: For the change in method `sparse6_string`, we check that the results are still correct. The sorted edges using the new way are stored in variable E1 and the sorted edges using the old way are stored in variable E2 and both are checked for equivalence:: sage: G = graphs.PetersenGraph() sage: E1 = G.edges() sage: E2 = copy(E1) sage: E1.sort(key=lambda e: (e[1],e[0])) sage: E2.sort(compare_edges) sage: if E1 != E2: ...       print "Error: sorting the new way is different from the old way!" Test some random graphs:: sage: for k in range(5): ...       g = graphs.RandomGNP(25+k,0.3) ...       E1 = g.edges() ...       E2 = copy(E1) ...       E1.sort(key=lambda e: (e[1],e[0])) ...       E2.sort(sage.graphs.graph.compare_edges) ...       if E1 != E2: ...           print "Error: sorting the new way is different from the old way!" doctest:...: DeprecationWarning: compare_edges(x,y) is deprecated.  Use statement 'cmp(x[1],y[1]) or cmp(x[0],y[0])' instead. See http://trac.sagemath.org/13192 for details. """ from sage.misc.superseded import deprecation deprecation(13192, "compare_edges(x,y) is deprecated.  Use statement 'cmp(x[1],y[1]) or cmp(x[0],y[0])' instead.") if x[1] < y[1]: return -1 elif x[1] > y[1]: