summarylogtreecommitdiffstats
path: root/sagemath-networkx2.patch
blob: 8090add150ce4730d9157b918dedeb7a6ad42663 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
diff --git a/src/sage/graphs/base/graph_backends.pyx b/src/sage/graphs/base/graph_backends.pyx
index ff1d02900a..bad4a18539 100644
--- a/src/sage/graphs/base/graph_backends.pyx
+++ b/src/sage/graphs/base/graph_backends.pyx
@@ -800,9 +800,9 @@ class NetworkXGraphDeprecated(SageObject):
             sage: X.multiedges = True
             sage: G = X.mutate()
             sage: G.edges()
-            [(1, 2), (2, 3)]
+            MultiEdgeDataView([(1, 2), (2, 3)])
             sage: G.edges(data=True)
-            [(1, 2, {'weight': 7}), (2, 3, {4: {}, 5: {}, 6: {}, 7: {}})]
+            MultiEdgeDataView([(1, 2, {'weight': 7}), (2, 3, {4: {}, 5: {}, 6: {}, 7: {}})])
 
         """
         import networkx
@@ -868,11 +868,9 @@ class NetworkXDiGraphDeprecated(SageObject):
             sage: X.multiedges = True
             sage: G = X.mutate()
             sage: G.edges()
-            [(1, 2), (2, 1), (2, 3)]
+            OutMultiEdgeDataView([(1, 2), (2, 1), (2, 3)])
             sage: G.edges(data=True)
-            [(1, 2, {'weight': 7}),
-             (2, 1, {7: {}, 8: {}}),
-             (2, 3, {4: {}, 5: {}, 6: {}, 7: {}})]
+            OutMultiEdgeDataView([(1, 2, {'weight': 7}), (2, 1, {8: {}, 7: {}}), (2, 3, {4: {}, 5: {}, 6: {}, 7: {}})])
 
         """
         import networkx
@@ -1154,7 +1152,7 @@ class NetworkXGraphBackend(GenericGraphBackend):
         import networkx
         try:
             if self._nxg.is_multigraph():
-                for k,d in self._nxg.edge[u][v].iteritems():
+                for u0,v0,k,d in self._nxg.edges([u,v],True,keys=True):
                     if d.get('weight',None) == l:
                         self._nxg.remove_edge(u,v,k)
                         break
@@ -1223,7 +1221,7 @@ class NetworkXGraphBackend(GenericGraphBackend):
         """
         cdef dict E
         try:
-            E = self._nxg.edge[u][v]
+            E = self._nxg.edges[u,v,0]
         except KeyError:
             from networkx import NetworkXError
             raise NetworkXError("Edge (%s,%s) requested via get_edge_label does not exist."%(u,v))
@@ -1412,7 +1410,7 @@ class NetworkXGraphBackend(GenericGraphBackend):
             sage: G.iterator_nbrs(0)
             <dictionary-keyiterator object at ...>
         """
-        return self._nxg.neighbors_iter(v)
+        return self._nxg.neighbors(v)
 
     def iterator_in_nbrs(self, v):
         """
diff --git a/src/sage/graphs/digraph.py b/src/sage/graphs/digraph.py
index 003a8d6bcb..986137a9b0 100644
--- a/src/sage/graphs/digraph.py
+++ b/src/sage/graphs/digraph.py
@@ -755,7 +755,7 @@ class DiGraph(GenericGraph):
             self.allow_multiple_edges(multiedges,check=False)
             self.allow_loops(loops,check=False)
             self.add_vertices(data.nodes())
-            self.add_edges((u,v,r(l)) for u,v,l in data.edges_iter(data=True))
+            self.add_edges((u,v,r(l)) for u,v,l in data.edges(data=True))
         elif format == 'igraph':
             if not data.is_directed():
                 raise ValueError("A *directed* igraph graph was expected. To "+
@@ -2846,7 +2846,7 @@ class DiGraph(GenericGraph):
         Using the NetworkX implementation ::
 
             sage: D.topological_sort(implementation = "NetworkX")
-            [4, 5, 6, 9, 0, 1, 2, 3, 7, 8, 10]
+            [4, 5, 6, 9, 0, 3, 2, 7, 1, 8, 10]
 
         Using the NetworkX recursive implementation ::
 
@@ -2872,9 +2872,7 @@ class DiGraph(GenericGraph):
               sage: D = DiGraph({ 0:[1,2,3], 4:[2,5], 1:[8], 2:[7], 3:[7],
               ....:   5:[6,7], 7:[8], 6:[9], 8:[10], 9:[10] })
               sage: N = D.networkx_graph()
-              sage: networkx.topological_sort(N)
-              [4, 5, 6, 9, 0, 1, 2, 3, 7, 8, 10]
-              sage: networkx.topological_sort_recursive(N)
+              sage: list(networkx.topological_sort(N))
               [4, 5, 6, 9, 0, 3, 2, 7, 1, 8, 10]
 
         TESTS:
@@ -2897,10 +2895,7 @@ class DiGraph(GenericGraph):
 
         elif implementation == "NetworkX" or implementation == "recursive":
             import networkx
-            if implementation == "NetworkX":
-                S = networkx.topological_sort(self.networkx_graph(copy=False))
-            else:
-                S = networkx.topological_sort_recursive(self.networkx_graph(copy=False))
+            S = list(networkx.topological_sort(self.networkx_graph(copy=False)))
             if S is None:
                 raise TypeError('Digraph is not acyclic; there is no topological sort.')
             else:
diff --git a/src/sage/graphs/generators/families.py b/src/sage/graphs/generators/families.py
index 8f81333685..1540ec0dcc 100644
--- a/src/sage/graphs/generators/families.py
+++ b/src/sage/graphs/generators/families.py
@@ -197,7 +197,7 @@ def BalancedTree(r, h):
     gracefully::
 
         sage: graphs.BalancedTree(1, 10)
-        Balanced tree: Graph on 2 vertices
+        Balanced tree: Graph on 11 vertices
 
         sage: graphs.BalancedTree(-1, 10)
         Balanced tree: Graph on 1 vertex
@@ -208,9 +208,6 @@ def BalancedTree(r, h):
         sage: graphs.BalancedTree(3, 0)
         Balanced tree: Graph on 1 vertex
 
-        sage: graphs.BalancedTree(5, -2)
-        Balanced tree: Graph on 0 vertices
-
         sage: graphs.BalancedTree(-2,-2)
         Balanced tree: Graph on 0 vertices
     """
diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py
index 3550f990ef..490813e619 100644
--- a/src/sage/graphs/graph.py
+++ b/src/sage/graphs/graph.py
@@ -1199,7 +1199,7 @@ class Graph(GenericGraph):
             self.allow_loops(loops, check=False)
             self.allow_multiple_edges(multiedges, check=False)
             self.add_vertices(data.nodes())
-            self.add_edges((u,v,r(l)) for u,v,l in data.edges_iter(data=True))
+            self.add_edges((u,v,r(l)) for u,v,l in data.edges(data=True))
         elif format == 'igraph':
             if data.is_directed():
                 raise ValueError("An *undirected* igraph graph was expected. "+
@@ -4621,7 +4621,7 @@ class Graph(GenericGraph):
 
             sage: g = Graph([(0,1,0), (1,2,999), (2,3,-5)])
             sage: g.matching(use_edge_labels=True)
-            [(1, 2, 999)]
+            [(0, 1, 0), (2, 3, -5)]
             sage: g.matching(algorithm="LP", use_edge_labels=True)
             [(1, 2, 999)]
 
@@ -4671,7 +4671,7 @@ class Graph(GenericGraph):
             else:
                 for u, v in L:
                     g.add_edge(u, v)
-            d = networkx.max_weight_matching(g)
+            d = dict(networkx.max_weight_matching(g).union(t[::-1] for t in networkx.max_weight_matching(g)))
             if value_only:
                 if use_edge_labels:
                     return sum(W[u, v] for u, v in six.iteritems(d) if u < v)
@@ -6305,7 +6305,7 @@ class Graph(GenericGraph):
         return networkx.number_of_cliques(self.networkx_graph(copy=False), vertices, cliques)
 
     @doc_index("Clique-related methods")
-    def cliques_get_max_clique_graph(self, name=''):
+    def cliques_get_max_clique_graph(self):
         """
         Return the clique graph.
 
@@ -6336,7 +6336,7 @@ class Graph(GenericGraph):
             sage: (G.cliques_get_max_clique_graph()).show(figsize=[2,2])
         """
         import networkx
-        return Graph(networkx.make_max_clique_graph(self.networkx_graph(copy=False), name=name, create_using=networkx.MultiGraph()))
+        return Graph(networkx.make_max_clique_graph(self.networkx_graph(copy=False), create_using=networkx.MultiGraph()))
 
     @doc_index("Clique-related methods")
     def cliques_get_clique_bipartite(self, **kwds):