Ticket #11182: trac_11182.patch

File trac_11182.patch, 11.4 KB (added by rlm, 10 years ago)
  • sage/graphs/bipartite_graph.py

    # HG changeset patch
    # User Robert L. Miller <rlm@rlmiller.org>
    # Date 1302639230 25200
    # Node ID 0fd28743cd399b25b0324ffd8a91088497a518fb
    # Parent  461868191947707e8c6a764078c3bec7274088a6
    #11181: edge labels should be unique
    
    diff -r 461868191947 -r 0fd28743cd39 sage/graphs/bipartite_graph.py
    a b  
    591591            sage: B.left
    592592            set([2])
    593593            sage: B.edges()
    594             [(1, 2, {}), (2, 3, {})]
     594            [(1, 2, None), (2, 3, None)]
    595595            sage: B.delete_vertex(3)
    596596            sage: B.right
    597597            set([1])
    598598            sage: B.edges()
    599             [(1, 2, {})]
     599            [(1, 2, None)]
    600600            sage: B.delete_vertex(0)
    601601            Traceback (most recent call last):
    602602            ...
     
    659659            sage: B.right
    660660            set([1])
    661661            sage: B.edges()
    662             [(1, 2, {})]
     662            [(1, 2, None)]
    663663            sage: B.delete_vertices([0])
    664664            Traceback (most recent call last):
    665665            ...
     
    964964            ...               if b != b2:
    965965            ...                   print "Load/save failed for code with edges:"
    966966            ...                   print b.edges()
     967            ...                   print b2.edges()
    967968            ...           except:
    968969            ...               print "Exception encountered for graph of order "+ str(order)
    969970            ...               print "with edges: "
  • sage/graphs/digraph.py

    diff -r 461868191947 -r 0fd28743cd39 sage/graphs/digraph.py
    a b  
    461461            format = 'NX'
    462462       
    463463        # At this point, format has been set.
     464       
     465        # adjust for empty dicts instead of None in NetworkX default edge labels
     466        kwds.setdefault('convert_empty_dict_labels_to_None', (format == 'NX'))
     467       
    464468        verts = None
    465469       
    466470        if format == 'dig6':
     
    706710                    if f(uu,vv):
    707711                        self.add_edge(uu,vv)
    708712        elif format == 'dict_of_dicts':
    709             for u in data:
    710                 for v in data[u]:
    711                     if multiedges:
    712                         self.add_edges([(u,v,l) for l in data[u][v]])
    713                     else:
    714                         self.add_edge((u,v,data[u][v]))
     713            if kwds.get('convert_empty_dict_labels_to_None', False):
     714                for u in data:
     715                    for v in data[u]:
     716                        if multiedges:
     717                            self.add_edges([(u,v,l) for l in data[u][v]])
     718                        else:
     719                            self.add_edge((u,v,data[u][v] if data[u][v] != {} else None))
     720            else:
     721                for u in data:
     722                    for v in data[u]:
     723                        if multiedges:
     724                            self.add_edges([(u,v,l) for l in data[u][v]])
     725                        else:
     726                            self.add_edge((u,v,data[u][v]))
    715727        elif format == 'dict_of_lists':
    716728            for u in data:
    717729                for v in data[u]:
  • sage/graphs/generic_graph.py

    diff -r 461868191947 -r 0fd28743cd39 sage/graphs/generic_graph.py
    a b  
    21072107            4
    21082108            sage: weight = lambda e: 1 / ((e[0] + 1) * (e[1] + 1))
    21092109            sage: g.min_spanning_tree(weight_function=weight)
    2110             [(3, 4, {}), (2, 4, {}), (1, 4, {}), (0, 4, {})]
     2110            [(3, 4, None), (2, 4, None), (1, 4, None), (0, 4, None)]
    21112111            sage: g = graphs.PetersenGraph()
    21122112            sage: g.allow_multiple_edges(True)
    21132113            sage: g.weighted(True)
     
    21192119
    21202120            sage: g = graphs.CompleteGraph(5)
    21212121            sage: g.min_spanning_tree(algorithm='Prim_edge', starting_vertex=2, weight_function=weight)
    2122             [(2, 4, {}), (3, 4, {}), (1, 4, {}), (0, 4, {})]
     2122            [(2, 4, None), (3, 4, None), (1, 4, None), (0, 4, None)]
    21232123            sage: g.min_spanning_tree(algorithm='Prim_fringe', starting_vertex=2, weight_function=weight)
    21242124            [(2, 4), (4, 3), (4, 1), (4, 0)]
    21252125        """
     
    72537253            sage: g=graphs.CycleGraph(3)
    72547254            sage: g.merge_vertices([0,1])
    72557255            sage: g.edges()
    7256             [(0, 2, {})]
     7256            [(0, 2, None)]
    72577257            sage: # With a Multigraph :
    72587258            sage: g=graphs.CycleGraph(3)
    72597259            sage: g.allow_multiple_edges(True)
    72607260            sage: g.merge_vertices([0,1])
    7261             sage: g.edges()
    7262             [(0, 2, {}), (0, 2, {})]
     7261            sage: g.edges(labels=False)
     7262            [(0, 2), (0, 2)]
    72637263            sage: P=graphs.PetersenGraph()
    72647264            sage: P.merge_vertices([5,7])
    72657265            sage: P.vertices()
     
    78407840        EXAMPLES::
    78417841
    78427842            sage: graphs.DodecahedralGraph().edges()
    7843             [(0, 1, {}), (0, 10, {}), (0, 19, {}), (1, 2, {}), (1, 8, {}), (2, 3, {}), (2, 6, {}), (3, 4, {}), (3, 19, {}), (4, 5, {}), (4, 17, {}), (5, 6, {}), (5, 15, {}), (6, 7, {}), (7, 8, {}), (7, 14, {}), (8, 9, {}), (9, 10, {}), (9, 13, {}), (10, 11, {}), (11, 12, {}), (11, 18, {}), (12, 13, {}), (12, 16, {}), (13, 14, {}), (14, 15, {}), (15, 16, {}), (16, 17, {}), (17, 18, {}), (18, 19, {})]
     7843            [(0, 1, None), (0, 10, None), (0, 19, None), (1, 2, None), (1, 8, None), (2, 3, None), (2, 6, None), (3, 4, None), (3, 19, None), (4, 5, None), (4, 17, None), (5, 6, None), (5, 15, None), (6, 7, None), (7, 8, None), (7, 14, None), (8, 9, None), (9, 10, None), (9, 13, None), (10, 11, None), (11, 12, None), (11, 18, None), (12, 13, None), (12, 16, None), (13, 14, None), (14, 15, None), (15, 16, None), (16, 17, None), (17, 18, None), (18, 19, None)]
    78447844
    78457845        ::
    78467846
     
    78517851
    78527852            sage: D = graphs.DodecahedralGraph().to_directed()
    78537853            sage: D.edges()
    7854             [(0, 1, {}), (0, 10, {}), (0, 19, {}), (1, 0, {}), (1, 2, {}), (1, 8, {}), (2, 1, {}), (2, 3, {}), (2, 6, {}), (3, 2, {}), (3, 4, {}), (3, 19, {}), (4, 3, {}), (4, 5, {}), (4, 17, {}), (5, 4, {}), (5, 6, {}), (5, 15, {}), (6, 2, {}), (6, 5, {}), (6, 7, {}), (7, 6, {}), (7, 8, {}), (7, 14, {}), (8, 1, {}), (8, 7, {}), (8, 9, {}), (9, 8, {}), (9, 10, {}), (9, 13, {}), (10, 0, {}), (10, 9, {}), (10, 11, {}), (11, 10, {}), (11, 12, {}), (11, 18, {}), (12, 11, {}), (12, 13, {}), (12, 16, {}), (13, 9, {}), (13, 12, {}), (13, 14, {}), (14, 7, {}), (14, 13, {}), (14, 15, {}), (15, 5, {}), (15, 14, {}), (15, 16, {}), (16, 12, {}), (16, 15, {}), (16, 17, {}), (17, 4, {}), (17, 16, {}), (17, 18, {}), (18, 11, {}), (18, 17, {}), (18, 19, {}), (19, 0, {}), (19, 3, {}), (19, 18, {})]
     7854            [(0, 1, None), (0, 10, None), (0, 19, None), (1, 0, None), (1, 2, None), (1, 8, None), (2, 1, None), (2, 3, None), (2, 6, None), (3, 2, None), (3, 4, None), (3, 19, None), (4, 3, None), (4, 5, None), (4, 17, None), (5, 4, None), (5, 6, None), (5, 15, None), (6, 2, None), (6, 5, None), (6, 7, None), (7, 6, None), (7, 8, None), (7, 14, None), (8, 1, None), (8, 7, None), (8, 9, None), (9, 8, None), (9, 10, None), (9, 13, None), (10, 0, None), (10, 9, None), (10, 11, None), (11, 10, None), (11, 12, None), (11, 18, None), (12, 11, None), (12, 13, None), (12, 16, None), (13, 9, None), (13, 12, None), (13, 14, None), (14, 7, None), (14, 13, None), (14, 15, None), (15, 5, None), (15, 14, None), (15, 16, None), (16, 12, None), (16, 15, None), (16, 17, None), (17, 4, None), (17, 16, None), (17, 18, None), (18, 11, None), (18, 17, None), (18, 19, None), (19, 0, None), (19, 3, None), (19, 18, None)]
    78557855            sage: D.edges(labels = False)
    78567856            [(0, 1), (0, 10), (0, 19), (1, 0), (1, 2), (1, 8), (2, 1), (2, 3), (2, 6), (3, 2), (3, 4), (3, 19), (4, 3), (4, 5), (4, 17), (5, 4), (5, 6), (5, 15), (6, 2), (6, 5), (6, 7), (7, 6), (7, 8), (7, 14), (8, 1), (8, 7), (8, 9), (9, 8), (9, 10), (9, 13), (10, 0), (10, 9), (10, 11), (11, 10), (11, 12), (11, 18), (12, 11), (12, 13), (12, 16), (13, 9), (13, 12), (13, 14), (14, 7), (14, 13), (14, 15), (15, 5), (15, 14), (15, 16), (16, 12), (16, 15), (16, 17), (17, 4), (17, 16), (17, 18), (18, 11), (18, 17), (18, 19), (19, 0), (19, 3), (19, 18)]
    78577857
     
    78617861
    78627862            sage: G=graphs.CycleGraph(5)
    78637863            sage: G.edges(key = lambda x: (x[1],-x[0]))
    7864             [(0, 1, {}), (1, 2, {}), (2, 3, {}), (3, 4, {}), (0, 4, {})]
     7864            [(0, 1, None), (1, 2, None), (2, 3, None), (3, 4, None), (0, 4, None)]
    78657865
    78667866        We set the labels to characters and then perform a default sort
    78677867        followed by a sort according to the labels. ::
     
    79357935
    79367936            sage: G = graphs.DiamondGraph()
    79377937            sage: G.edge_boundary([0,1])
    7938             [(0, 2, {}), (1, 2, {}), (1, 3, {})]
     7938            [(0, 2, None), (1, 2, None), (1, 3, None)]
    79397939            sage: G.edge_boundary([0], [0])
    79407940            []
    79417941            sage: G.edge_boundary([2], [0])
    7942             [(0, 2, {})]
     7942            [(0, 2, None)]
    79437943        """
    79447944        vertices1 = set([v for v in vertices1 if v in self])
    79457945        if self._directed:
  • sage/graphs/graph.py

    diff -r 461868191947 -r 0fd28743cd39 sage/graphs/graph.py
    a b  
    960960            format = 'NX'
    961961       
    962962        # At this point, format has been set.
     963       
     964        # adjust for empty dicts instead of None in NetworkX default edge labels
     965        kwds.setdefault('convert_empty_dict_labels_to_None', (format == 'NX'))
    963966
    964967        verts = None
    965968       
     
    12571260                    if f(uu,vv):
    12581261                        self.add_edge(uu,vv)
    12591262        elif format == 'dict_of_dicts':
    1260             for u in data:
    1261                 for v in data[u]:
    1262                     if hash(u) <= hash(v) or v not in data or u not in data[v]:
    1263                         if multiedges:
    1264                             self.add_edges([(u,v,l) for l in data[u][v]])
    1265                         else:
    1266                             self.add_edge((u,v,data[u][v]))
     1263            if kwds.get('convert_empty_dict_labels_to_None', False):
     1264                for u in data:
     1265                    for v in data[u]:
     1266                        if hash(u) <= hash(v) or v not in data or u not in data[v]:
     1267                            if multiedges:
     1268                                self.add_edges([(u,v,l) for l in data[u][v]])
     1269                            else:
     1270                                self.add_edge((u,v,data[u][v] if data[u][v] != {} else None))
     1271            else:
     1272                for u in data:
     1273                    for v in data[u]:
     1274                        if hash(u) <= hash(v) or v not in data or u not in data[v]:
     1275                            if multiedges:
     1276                                self.add_edges([(u,v,l) for l in data[u][v]])
     1277                            else:
     1278                                self.add_edge((u,v,data[u][v]))
    12671279        elif format == 'dict_of_lists':
    12681280            for u in data:
    12691281                for v in data[u]:
     
    16271639       
    16281640            sage: g=graphs.CycleGraph(5);
    16291641            sage: g.eulerian_circuit()
    1630             [(0, 1, {}), (1, 2, {}), (2, 3, {}), (3, 4, {}), (4, 0, {})]
     1642            [(0, 1, None), (1, 2, None), (2, 3, None), (3, 4, None), (4, 0, None)]
    16311643            sage: g.eulerian_circuit(labels=False)
    16321644            [(0, 1), (1, 2), (2, 3), (3, 4), (4, 0)]
    16331645            sage: g = graphs.CompleteGraph(7)