diff options
Diffstat (limited to 'sci-mathematics/sage/files/trac_9567-networkx-1.2.patch')
-rw-r--r-- | sci-mathematics/sage/files/trac_9567-networkx-1.2.patch | 329 |
1 files changed, 329 insertions, 0 deletions
diff --git a/sci-mathematics/sage/files/trac_9567-networkx-1.2.patch b/sci-mathematics/sage/files/trac_9567-networkx-1.2.patch new file mode 100644 index 0000000..51ba3fb --- /dev/null +++ b/sci-mathematics/sage/files/trac_9567-networkx-1.2.patch @@ -0,0 +1,329 @@ +# HG changeset patch +# User Ben Edwards <bedwards@cs.unm.edu> +# Date 1281372187 21600 +# Node ID 2f4945743e05e93fdbae5ec75777060bea4a6670 +# Parent 5b338f2e484f2065d3d30d47bc204d6e9ed13d12 +trac 9567: Updates to sage to interface with new version of networkx(1.2) + +This also includes several changes to the sage graph API to return +keyed dictionaries instead of lists, as this is preferred in many +situations. + +diff -r 5b338f2e484f -r 2f4945743e05 sage/graphs/generic_graph.py +--- a/sage/graphs/generic_graph.py Thu Aug 05 03:35:44 2010 -0700 ++++ b/sage/graphs/generic_graph.py Mon Aug 09 10:43:07 2010 -0600 +@@ -8478,8 +8478,8 @@ + + def cluster_triangles(self, nbunch=None, with_labels=False): + r""" +- Returns the number of triangles for nbunch of vertices as an +- ordered list. ++ Returns the number of triangles for nbunch of vertices as a ++ dictionary keyed by vertex. + + The clustering coefficient of a graph is the fraction of possible + triangles that are triangles, `c_i = triangles_i / +@@ -8494,9 +8494,6 @@ + - ``nbunch`` - The vertices to inspect. If + nbunch=None, returns data for all vertices in the graph + +- - ``with_labels`` - (boolean) default False +- returns list as above True returns dict keyed by vertex labels. +- + + REFERENCE: + +@@ -8506,15 +8503,15 @@ + + EXAMPLES:: + ++ sage: (graphs.FruchtGraph()).cluster_triangles().values() ++ [1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0] + sage: (graphs.FruchtGraph()).cluster_triangles() +- [1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0] +- sage: (graphs.FruchtGraph()).cluster_triangles(with_labels=True) + {0: 1, 1: 1, 2: 0, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 0, 9: 1, 10: 1, 11: 0} + sage: (graphs.FruchtGraph()).cluster_triangles(nbunch=[0,1,2]) +- [1, 1, 0] ++ {0: 1, 1: 1, 2: 0} + """ + import networkx +- return networkx.triangles(self.networkx_graph(copy=False), nbunch, with_labels) ++ return networkx.triangles(self.networkx_graph(copy=False), nbunch) + + def clustering_average(self): + r""" +@@ -8541,10 +8538,10 @@ + import networkx + return networkx.average_clustering(self.networkx_graph(copy=False)) + +- def clustering_coeff(self, nbunch=None, with_labels=False, weights=False): +- r""" +- Returns the clustering coefficient for each vertex in nbunch as an +- ordered list. ++ def clustering_coeff(self, nbunch=None, weights=False): ++ r""" ++ Returns the clustering coefficient for each vertex in nbunch as a ++ dictionary keyed by vertex. + + The clustering coefficient of a graph is the fraction of possible + triangles that are triangles, `c_i = triangles_i / +@@ -8558,9 +8555,6 @@ + - ``nbunch`` - the vertices to inspect (default + None returns data on all vertices in graph) + +- - ``with_labels`` - (boolean) default False +- returns list as above True returns dict keyed by vertex labels. +- + - ``weights`` - default is False. If both + with_labels and weights are True, then returns a clustering + coefficient dict and a dict of weights based on degree. Weights are +@@ -8576,19 +8570,19 @@ + + EXAMPLES:: + ++ sage: (graphs.FruchtGraph()).clustering_coeff().values() ++ [0.33333333333333331, 0.33333333333333331, 0.0, 0.33333333333333331, 0.33333333333333331, 0.33333333333333331, 0.33333333333333331, 0.33333333333333331, 0.0, 0.33333333333333331, 0.33333333333333331, 0.0] + sage: (graphs.FruchtGraph()).clustering_coeff() +- [0.33333333333333331, 0.33333333333333331, 0.0, 0.33333333333333331, 0.33333333333333331, 0.33333333333333331, 0.33333333333333331, 0.33333333333333331, 0.0, 0.33333333333333331, 0.33333333333333331, 0.0] +- sage: (graphs.FruchtGraph()).clustering_coeff(with_labels=True) + {0: 0.33333333333333331, 1: 0.33333333333333331, 2: 0.0, 3: 0.33333333333333331, 4: 0.33333333333333331, 5: 0.33333333333333331, 6: 0.33333333333333331, 7: 0.33333333333333331, 8: 0.0, 9: 0.33333333333333331, 10: 0.33333333333333331, 11: 0.0} +- sage: (graphs.FruchtGraph()).clustering_coeff(with_labels=True,weights=True) ++ sage: (graphs.FruchtGraph()).clustering_coeff(weights=True) + ({0: 0.33333333333333331, 1: 0.33333333333333331, 2: 0.0, 3: 0.33333333333333331, 4: 0.33333333333333331, 5: 0.33333333333333331, 6: 0.33333333333333331, 7: 0.33333333333333331, 8: 0.0, 9: 0.33333333333333331, 10: 0.33333333333333331, 11: 0.0}, {0: 0.083333333333333329, 1: 0.083333333333333329, 2: 0.083333333333333329, 3: 0.083333333333333329, 4: 0.083333333333333329, 5: 0.083333333333333329, 6: 0.083333333333333329, 7: 0.083333333333333329, 8: 0.083333333333333329, 9: 0.083333333333333329, 10: 0.083333333333333329, 11: 0.083333333333333329}) + sage: (graphs.FruchtGraph()).clustering_coeff(nbunch=[0,1,2]) +- [0.33333333333333331, 0.33333333333333331, 0.0] +- sage: (graphs.FruchtGraph()).clustering_coeff(nbunch=[0,1,2],with_labels=True,weights=True) ++ {0: 0.33333333333333331, 1: 0.33333333333333331, 2: 0.0} ++ sage: (graphs.FruchtGraph()).clustering_coeff(nbunch=[0,1,2],weights=True) + ({0: 0.33333333333333331, 1: 0.33333333333333331, 2: 0.0}, {0: 0.33333333333333331, 1: 0.33333333333333331, 2: 0.33333333333333331}) + """ + import networkx +- return networkx.clustering(self.networkx_graph(copy=False), nbunch, with_labels, weights) ++ return networkx.clustering(self.networkx_graph(copy=False), nbunch, weights) + + def cluster_transitivity(self): + r""" +diff -r 5b338f2e484f -r 2f4945743e05 sage/graphs/graph.py +--- a/sage/graphs/graph.py Thu Aug 05 03:35:44 2010 -0700 ++++ b/sage/graphs/graph.py Mon Aug 09 10:43:07 2010 -0600 +@@ -2531,7 +2531,7 @@ + sage: (graphs.ChvatalGraph()).centrality_betweenness() + {0: 0.069696969696969688, 1: 0.069696969696969688, 2: 0.060606060606060601, 3: 0.060606060606060601, 4: 0.069696969696969688, 5: 0.069696969696969688, 6: 0.060606060606060601, 7: 0.060606060606060601, 8: 0.060606060606060601, 9: 0.060606060606060601, 10: 0.060606060606060601, 11: 0.060606060606060601} + sage: (graphs.ChvatalGraph()).centrality_betweenness(normalized=False) +- {0: 7.6666666666666661, 1: 7.6666666666666661, 2: 6.6666666666666661, 3: 6.6666666666666661, 4: 7.6666666666666661, 5: 7.6666666666666661, 6: 6.6666666666666661, 7: 6.6666666666666661, 8: 6.6666666666666661, 9: 6.6666666666666661, 10: 6.6666666666666661, 11: 6.6666666666666661} ++ {0: 3.833333333333333, 1: 3.833333333333333, 2: 3.333333333333333, 3: 3.333333333333333, 4: 3.833333333333333, 5: 3.833333333333333, 6: 3.333333333333333, 7: 3.333333333333333, 8: 3.333333333333333, 9: 3.333333333333333, 10: 3.333333333333333, 11: 3.333333333333333} + sage: D = DiGraph({0:[1,2,3], 1:[2], 3:[0,1]}) + sage: D.show(figsize=[2,2]) + sage: D = D.to_undirected() +@@ -2573,7 +2573,10 @@ + 1.0 + """ + import networkx +- return networkx.degree_centrality(self.networkx_graph(copy=False), v) ++ if v==None: ++ return networkx.degree_centrality(self.networkx_graph(copy=False)) ++ else: ++ return networkx.degree_centrality(self.networkx_graph(copy=False))[v] + + def centrality_closeness(self, v=None): + r""" +@@ -2870,10 +2873,11 @@ + else: + raise NotImplementedError("Only 'networkx' and 'cliquer' are supported.") + +- def cliques_number_of(self, vertices=None, cliques=None, with_labels=False): ++ def cliques_number_of(self, vertices=None, cliques=None): + """ +- Returns a list of the number of maximal cliques containing each +- vertex. (Returns a single value if only one input vertex). ++ Returns a dictionary of the number of maximal cliques containing each ++ vertex, keyed by vertex. (Returns a single value if ++ only one input vertex). + + .. NOTE:: + +@@ -2885,9 +2889,6 @@ + - ``vertices`` - the vertices to inspect (default is + entire graph) + +- - ``with_labels`` - (boolean) default False returns +- list as above True returns a dictionary keyed by vertex labels +- + - ``cliques`` - list of cliques (if already + computed) + +@@ -2896,14 +2897,14 @@ + + sage: C = Graph('DJ{') + sage: C.cliques_number_of() +- [1, 1, 1, 1, 2] ++ {0: 1, 1: 1, 2: 1, 3: 1, 4: 2} + sage: E = C.cliques_maximal() + sage: E + [[4, 0], [4, 1, 2, 3]] + sage: C.cliques_number_of(cliques=E) +- [1, 1, 1, 1, 2] ++ {0: 1, 1: 1, 2: 1, 3: 1, 4: 2} + sage: F = graphs.Grid2dGraph(2,3) +- sage: X = F.cliques_number_of(with_labels=True) ++ sage: X = F.cliques_number_of() + sage: for v in sorted(X.iterkeys()): + ... print v, X[v] + (0, 0) 2 +@@ -2913,14 +2914,14 @@ + (1, 1) 3 + (1, 2) 2 + sage: F.cliques_number_of(vertices=[(0, 1), (1, 2)]) +- [3, 2] ++ {(0, 1): 3, (1, 2): 2} + sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]}) + sage: G.show(figsize=[2,2]) + sage: G.cliques_number_of() +- [2, 2, 1, 1] ++ {0: 2, 1: 2, 2: 1, 3: 1} + """ + import networkx +- return networkx.number_of_cliques(self.networkx_graph(copy=False), vertices, cliques, with_labels) ++ return networkx.number_of_cliques(self.networkx_graph(copy=False), vertices, cliques) + + def cliques_get_max_clique_graph(self, name=''): + """ +@@ -2996,12 +2997,13 @@ + """ + from sage.graphs.cliquer import max_clique + return max_clique(self.complement()) +- ++ + def cliques_vertex_clique_number(self, algorithm="cliquer", vertices=None, +- with_labels=False, cliques=None): +- r""" +- Returns a list of sizes of the largest maximal cliques containing +- each vertex. (Returns a single value if only one input vertex). ++ cliques=None): ++ """ ++ Returns a dictionary of sizes of the largest maximal cliques containing ++ each vertex, keyed by vertex. (Returns a single value if only one ++ input vertex). + + .. NOTE:: + +@@ -3020,10 +3022,6 @@ + - ``vertices`` - the vertices to inspect (default is entire graph). + Ignored unless ``algorithm=='networkx'``. + +- - ``with_labels`` - (boolean) default False returns list as above +- True returns a dictionary keyed by vertex labels. Ignored unless +- ``algorithm=='networkx'``. +- + - ``cliques`` - list of cliques (if already computed). Ignored unless + ``algorithm=='networkx'``. + +@@ -3031,14 +3029,14 @@ + + sage: C = Graph('DJ{') + sage: C.cliques_vertex_clique_number() +- [2, 4, 4, 4, 4] ++ {0: 2, 1: 4, 2: 4, 3: 4, 4: 4} + sage: E = C.cliques_maximal() + sage: E + [[4, 0], [4, 1, 2, 3]] + sage: C.cliques_vertex_clique_number(cliques=E,algorithm="networkx") +- [2, 4, 4, 4, 4] ++ {0: 2, 1: 4, 2: 4, 3: 4, 4: 4} + sage: F = graphs.Grid2dGraph(2,3) +- sage: X = F.cliques_vertex_clique_number(with_labels=True,algorithm="networkx") ++ sage: X = F.cliques_vertex_clique_number(algorithm="networkx") + sage: for v in sorted(X.iterkeys()): + ... print v, X[v] + (0, 0) 2 +@@ -3048,11 +3046,11 @@ + (1, 1) 2 + (1, 2) 2 + sage: F.cliques_vertex_clique_number(vertices=[(0, 1), (1, 2)]) +- [2, 2] ++ {(0, 1): 2, (1, 2): 2} + sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]}) + sage: G.show(figsize=[2,2]) + sage: G.cliques_vertex_clique_number() +- [3, 3, 3, 3] ++ {0: 3, 1: 3, 2: 3, 3: 3} + + """ + +@@ -3060,21 +3058,22 @@ + from sage.graphs.cliquer import clique_number + if vertices==None: + vertices=self +- value=[] ++ value={} + for v in vertices: +- value.append(1+clique_number(self.subgraph(self.neighbors(v)))) ++ value[v] = 1+clique_number(self.subgraph(self.neighbors(v))) + self.subgraph(self.neighbors(v)).plot() + return value + elif algorithm=="networkx": + import networkx +- return networkx.node_clique_number(self.networkx_graph(copy=False), vertices, with_labels, cliques) ++ return networkx.node_clique_number(self.networkx_graph(copy=False),vertices, cliques) + else: + raise NotImplementedError("Only 'networkx' and 'cliquer' are supported.") + +- def cliques_containing_vertex(self, vertices=None, cliques=None, with_labels=False): ++ def cliques_containing_vertex(self, vertices=None, cliques=None): + """ +- Returns the cliques containing each vertex, represented as a list +- of lists. (Returns a single list if only one input vertex). ++ Returns the cliques containing each vertex, represented as a dictionary ++ of lists of lists, keyed by vertex. (Returns a single list if only one ++ input vertex). + + .. NOTE:: + +@@ -3086,9 +3085,6 @@ + - ``vertices`` - the vertices to inspect (default is + entire graph) + +- - ``with_labels`` - (boolean) default False returns +- list as above True returns a dictionary keyed by vertex labels +- + - ``cliques`` - list of cliques (if already + computed) + +@@ -3096,14 +3092,14 @@ + + sage: C = Graph('DJ{') + sage: C.cliques_containing_vertex() +- [[[4, 0]], [[4, 1, 2, 3]], [[4, 1, 2, 3]], [[4, 1, 2, 3]], [[4, 0], [4, 1, 2, 3]]] ++ {0: [[4, 0]], 1: [[4, 1, 2, 3]], 2: [[4, 1, 2, 3]], 3: [[4, 1, 2, 3]], 4: [[4, 0], [4, 1, 2, 3]]} + sage: E = C.cliques_maximal() + sage: E + [[4, 0], [4, 1, 2, 3]] + sage: C.cliques_containing_vertex(cliques=E) +- [[[4, 0]], [[4, 1, 2, 3]], [[4, 1, 2, 3]], [[4, 1, 2, 3]], [[4, 0], [4, 1, 2, 3]]] ++ {0: [[4, 0]], 1: [[4, 1, 2, 3]], 2: [[4, 1, 2, 3]], 3: [[4, 1, 2, 3]], 4: [[4, 0], [4, 1, 2, 3]]} + sage: F = graphs.Grid2dGraph(2,3) +- sage: X = F.cliques_containing_vertex(with_labels=True) ++ sage: X = F.cliques_containing_vertex() + sage: for v in sorted(X.iterkeys()): + ... print v, X[v] + (0, 0) [[(0, 1), (0, 0)], [(1, 0), (0, 0)]] +@@ -3113,15 +3109,15 @@ + (1, 1) [[(0, 1), (1, 1)], [(1, 2), (1, 1)], [(1, 0), (1, 1)]] + (1, 2) [[(1, 2), (0, 2)], [(1, 2), (1, 1)]] + sage: F.cliques_containing_vertex(vertices=[(0, 1), (1, 2)]) +- [[[(0, 1), (0, 0)], [(0, 1), (0, 2)], [(0, 1), (1, 1)]], [[(1, 2), (0, 2)], [(1, 2), (1, 1)]]] ++ {(0, 1): [[(0, 1), (0, 0)], [(0, 1), (0, 2)], [(0, 1), (1, 1)]], (1, 2): [[(1, 2), (0, 2)], [(1, 2), (1, 1)]]} + sage: G = Graph({0:[1,2,3], 1:[2], 3:[0,1]}) + sage: G.show(figsize=[2,2]) + sage: G.cliques_containing_vertex() +- [[[0, 1, 2], [0, 1, 3]], [[0, 1, 2], [0, 1, 3]], [[0, 1, 2]], [[0, 1, 3]]] ++ {0: [[0, 1, 2], [0, 1, 3]], 1: [[0, 1, 2], [0, 1, 3]], 2: [[0, 1, 2]], 3: [[0, 1, 3]]} + + """ + import networkx +- return networkx.cliques_containing_node(self.networkx_graph(copy=False), vertices, cliques, with_labels) ++ return networkx.cliques_containing_node(self.networkx_graph(copy=False),vertices, cliques) + + def clique_complex(self): + """ |