diff --git a/src/sage/graphs/base/static_sparse_graph.pyx b/src/sage/graphs/base/static_sparse_graph.pyx index 6c4bc1b7edd..22509f2028c 100644 --- a/src/sage/graphs/base/static_sparse_graph.pyx +++ b/src/sage/graphs/base/static_sparse_graph.pyx @@ -732,8 +732,8 @@ def tarjan_strongly_connected_components(G): Checking against NetworkX:: - sage: import networkx - sage: for i in range(10): # long time + sage: import networkx # optional - networkx + sage: for i in range(10): # long time # optional - networkx ....: g = digraphs.RandomDirectedGNP(100,.05) ....: h = g.networkx_graph() ....: scc1 = g.strongly_connected_components() diff --git a/src/sage/graphs/bipartite_graph.py b/src/sage/graphs/bipartite_graph.py index 62089c773da..dc68357dccf 100644 --- a/src/sage/graphs/bipartite_graph.py +++ b/src/sage/graphs/bipartite_graph.py @@ -308,10 +308,10 @@ class BipartiteGraph(Graph): #. From a NetworkX bipartite graph:: - sage: import networkx - sage: G = graphs.OctahedralGraph() - sage: N = networkx.make_clique_bipartite(G.networkx_graph()) - sage: B = BipartiteGraph(N) + sage: import networkx # optional - networkx + sage: G = graphs.OctahedralGraph() # optional - networkx + sage: N = networkx.make_clique_bipartite(G.networkx_graph()) # optional - networkx + sage: B = BipartiteGraph(N) # optional - networkx TESTS: diff --git a/src/sage/graphs/centrality.pyx b/src/sage/graphs/centrality.pyx index 852b86c34e8..91f0fc21a52 100755 --- a/src/sage/graphs/centrality.pyx +++ b/src/sage/graphs/centrality.pyx @@ -99,11 +99,11 @@ def centrality_betweenness(G, bint exact=False, bint normalize=True): Compare with NetworkX:: - sage: import networkx - sage: g = graphs.RandomGNP(100, .2) - sage: nw = networkx.betweenness_centrality(g.networkx_graph()) - sage: sg = centrality_betweenness(g) - sage: max(abs(nw[x] - sg[x]) for x in g) # abs tol 1e-10 + sage: import networkx # optional - networkx + sage: g = graphs.RandomGNP(100, .2) # optional - networkx + sage: nw = networkx.betweenness_centrality(g.networkx_graph()) # optional - networkx + sage: sg = centrality_betweenness(g) # optional - networkx + sage: max(abs(nw[x] - sg[x]) for x in g) # abs tol 1e-10 # optional - networkx 0 Stupid cases:: diff --git a/src/sage/graphs/digraph.py b/src/sage/graphs/digraph.py index 2a63c18f3b1..4a3ccf3da78 100644 --- a/src/sage/graphs/digraph.py +++ b/src/sage/graphs/digraph.py @@ -427,17 +427,17 @@ class DiGraph(GenericGraph): #. A NetworkX MultiDiGraph:: - sage: import networkx - sage: g = networkx.MultiDiGraph({0: [1, 2, 3], 2: [4]}) - sage: DiGraph(g) + sage: import networkx # optional - networkx + sage: g = networkx.MultiDiGraph({0: [1, 2, 3], 2: [4]}) # optional - networkx + sage: DiGraph(g) # optional - networkx Multi-digraph on 5 vertices #. A NetworkX digraph:: - sage: import networkx - sage: g = networkx.DiGraph({0: [1, 2, 3], 2: [4]}) - sage: DiGraph(g) + sage: import networkx # optional - networkx + sage: g = networkx.DiGraph({0: [1, 2, 3], 2: [4]}) # optional - networkx + sage: DiGraph(g) # optional - networkx Digraph on 5 vertices #. An igraph directed Graph (see also @@ -477,18 +477,18 @@ class DiGraph(GenericGraph): Demonstrate that digraphs using the static backend are equal to mutable graphs but can be used as dictionary keys:: - sage: import networkx - sage: g = networkx.DiGraph({0:[1,2,3], 2:[4]}) - sage: G = DiGraph(g) - sage: G_imm = DiGraph(G, data_structure="static_sparse") - sage: H_imm = DiGraph(G, data_structure="static_sparse") - sage: H_imm is G_imm + sage: import networkx # optional - networkx + sage: g = networkx.DiGraph({0:[1,2,3], 2:[4]}) # optional - networkx + sage: G = DiGraph(g) # optional - networkx + sage: G_imm = DiGraph(G, data_structure="static_sparse") # optional - networkx + sage: H_imm = DiGraph(G, data_structure="static_sparse") # optional - networkx + sage: H_imm is G_imm # optional - networkx False - sage: H_imm == G_imm == G + sage: H_imm == G_imm == G # optional - networkx True - sage: {G_imm:1}[H_imm] + sage: {G_imm:1}[H_imm] # optional - networkx 1 - sage: {G_imm:1}[G] + sage: {G_imm:1}[G] # optional - networkx Traceback (most recent call last): ... TypeError: This graph is mutable, and thus not hashable. Create an @@ -498,10 +498,10 @@ class DiGraph(GenericGraph): specifying the ``immutable`` optional argument (not only by ``data_structure='static_sparse'`` as above):: - sage: J_imm = DiGraph(G, immutable=True) - sage: J_imm == G_imm + sage: J_imm = DiGraph(G, immutable=True) # optional - networkx + sage: J_imm == G_imm # optional - networkx True - sage: type(J_imm._backend) == type(G_imm._backend) + sage: type(J_imm._backend) == type(G_imm._backend) # optional - networkx True From a list of vertices and a list of edges:: @@ -513,7 +513,7 @@ class DiGraph(GenericGraph): Check that :trac:`27505` is fixed:: - sage: DiGraph(DiGraph().networkx_graph(), weighted=None, format='NX') + sage: DiGraph(DiGraph().networkx_graph(), weighted=None, format='NX') # optional - networkx Digraph on 0 vertices """ _directed = True diff --git a/src/sage/graphs/generators/basic.py b/src/sage/graphs/generators/basic.py index 84d520dd969..a685f6cc233 100644 --- a/src/sage/graphs/generators/basic.py +++ b/src/sage/graphs/generators/basic.py @@ -248,12 +248,12 @@ def CycleGraph(n): Compare plotting using the predefined layout and networkx:: - sage: import networkx - sage: n = networkx.cycle_graph(23) - sage: spring23 = Graph(n) - sage: posdict23 = graphs.CycleGraph(23) - sage: spring23.show() # long time - sage: posdict23.show() # long time + sage: import networkx # optional - networkx + sage: n = networkx.cycle_graph(23) # optional - networkx + sage: spring23 = Graph(n) # optional - networkx + sage: posdict23 = graphs.CycleGraph(23) # optional - networkx + sage: spring23.show() # long time # optional - networkx + sage: posdict23.show() # long time # optional - networkx We next view many cycle graphs as a Sage graphics array. First we use the ``CycleGraph`` constructor, which fills in the position dictionary:: @@ -275,17 +275,17 @@ def CycleGraph(n): sage: g = [] sage: j = [] - sage: for i in range(9): + sage: for i in range(9): # optional - networkx ....: spr = networkx.cycle_graph(i+3) ....: k = Graph(spr) ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - networkx ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - networkx + sage: G.show() # long time # optional - networkx TESTS: @@ -349,27 +349,27 @@ def CompleteGraph(n): We compare to plotting with the spring-layout algorithm:: - sage: import networkx + sage: import networkx # optional - networkx sage: g = [] sage: j = [] - sage: for i in range(9): + sage: for i in range(9): # optional - networkx ....: spr = networkx.complete_graph(i+3) ....: k = Graph(spr) ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - networkx ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - networkx + sage: G.show() # long time # optional - networkx Compare the constructors (results will vary):: - sage: import networkx - sage: t = cputime() - sage: n = networkx.complete_graph(389); spring389 = Graph(n) - sage: cputime(t) # random + sage: import networkx # optional - networkx + sage: t = cputime() # optional - networkx + sage: n = networkx.complete_graph(389); spring389 = Graph(n) # optional - networkx + sage: cputime(t) # random # optional - networkx 0.59203700000000126 sage: t = cputime() sage: posdict389 = graphs.CompleteGraph(389) @@ -378,11 +378,11 @@ def CompleteGraph(n): We compare plotting:: - sage: import networkx - sage: n = networkx.complete_graph(23) + sage: import networkx # optional - networkx + sage: n = networkx.complete_graph(23) # optional - networkx sage: spring23 = Graph(n) sage: posdict23 = graphs.CompleteGraph(23) - sage: spring23.show() # long time + sage: spring23.show() # long time # optional - networkx sage: posdict23.show() # long time """ G = Graph(n, name="Complete graph") @@ -438,19 +438,19 @@ def CompleteBipartiteGraph(p, q, set_position=True): Two ways of constructing the complete bipartite graph, using different layout algorithms:: - sage: import networkx - sage: n = networkx.complete_bipartite_graph(389, 157); spring_big = Graph(n) # long time + sage: import networkx # optional - networkx + sage: n = networkx.complete_bipartite_graph(389, 157); spring_big = Graph(n) # long time # optional - networkx sage: posdict_big = graphs.CompleteBipartiteGraph(389, 157) # long time Compare the plotting:: - sage: n = networkx.complete_bipartite_graph(11, 17) - sage: spring_med = Graph(n) + sage: n = networkx.complete_bipartite_graph(11, 17) # optional - networkx + sage: spring_med = Graph(n) # optional - networkx sage: posdict_med = graphs.CompleteBipartiteGraph(11, 17) Notice here how the spring-layout tends to center the nodes of `n1`:: - sage: spring_med.show() # long time + sage: spring_med.show() # long time # optional - networkx sage: posdict_med.show() # long time View many complete bipartite graphs with a Sage Graphics Array, with this @@ -473,17 +473,17 @@ def CompleteBipartiteGraph(p, q, set_position=True): sage: g = [] sage: j = [] - sage: for i in range(9): + sage: for i in range(9): # optional - networkx ....: spr = networkx.complete_bipartite_graph(i+1,4) ....: k = Graph(spr) ....: g.append(k) - sage: for i in range(3): + sage: for i in range(3): # optional - networkx ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - networkx + sage: G.show() # long time # optional - networkx :trac:`12155`:: @@ -933,9 +933,9 @@ def GridGraph(dim_list): sage: dim = [randint(1,4) for i in range(4)] sage: g = graphs.GridGraph(dim) - sage: import networkx - sage: h = Graph( networkx.grid_graph(list(dim)) ) - sage: g.is_isomorphic(h) + sage: import networkx # optional - networkx + sage: h = Graph(networkx.grid_graph(list(dim))) # optional - networkx + sage: g.is_isomorphic(h) # optional - networkx True Trivial cases:: @@ -1223,14 +1223,14 @@ def StarGraph(n): EXAMPLES:: - sage: import networkx + sage: import networkx # optional - networkx Compare the plots:: - sage: n = networkx.star_graph(23) - sage: spring23 = Graph(n) + sage: n = networkx.star_graph(23) # optional - networkx + sage: spring23 = Graph(n) # optional - networkx sage: posdict23 = graphs.StarGraph(23) - sage: spring23.show() # long time + sage: spring23.show() # long time # optional - networkx sage: posdict23.show() # long time View many star graphs as a Sage Graphics Array diff --git a/src/sage/graphs/generators/families.py b/src/sage/graphs/generators/families.py index 9dd7bc1cb1e..ccd8af1ff25 100644 --- a/src/sage/graphs/generators/families.py +++ b/src/sage/graphs/generators/families.py @@ -1076,11 +1076,11 @@ def CirculantGraph(n, adjacency): EXAMPLES: Compare plotting using the predefined layout and networkx:: - sage: import networkx - sage: n = networkx.cycle_graph(23) - sage: spring23 = Graph(n) + sage: import networkx # optional - networkx + sage: n = networkx.cycle_graph(23) # optional - networkx + sage: spring23 = Graph(n) # optional - networkx sage: posdict23 = graphs.CirculantGraph(23,2) - sage: spring23.show() # long time + sage: spring23.show() # long time # optional - networkx sage: posdict23.show() # long time We next view many cycle graphs as a Sage graphics array. First we @@ -3409,29 +3409,29 @@ def WheelGraph(n): Next, using the spring-layout algorithm:: - sage: import networkx + sage: import networkx # optional - networkx sage: g = [] sage: j = [] - sage: for i in range(9): + sage: for i in range(9): # optional - networkx ....: spr = networkx.wheel_graph(i+3) ....: k = Graph(spr) ....: g.append(k) ... - sage: for i in range(3): + sage: for i in range(3): # optional - networkx ....: n = [] ....: for m in range(3): ....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) ... - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - networkx + sage: G.show() # long time # optional - networkx Compare the plotting:: - sage: n = networkx.wheel_graph(23) - sage: spring23 = Graph(n) + sage: n = networkx.wheel_graph(23) # optional - networkx + sage: spring23 = Graph(n) # optional - networkx sage: posdict23 = graphs.WheelGraph(23) - sage: spring23.show() # long time + sage: spring23.show() # long time # optional - networkx sage: posdict23.show() # long time """ from sage.graphs.generators.basic import CycleGraph diff --git a/src/sage/graphs/generators/platonic_solids.py b/src/sage/graphs/generators/platonic_solids.py index f6244d587ea..536a5f155e6 100644 --- a/src/sage/graphs/generators/platonic_solids.py +++ b/src/sage/graphs/generators/platonic_solids.py @@ -43,24 +43,24 @@ def TetrahedralGraph(): The following example requires networkx:: - sage: import networkx as NX + sage: import networkx as NX # optional - networkx Compare this Tetrahedral, Wheel(4), Complete(4), and the Tetrahedral plotted with the spring-layout algorithm below in a Sage graphics array:: sage: tetra_pos = graphs.TetrahedralGraph() - sage: tetra_spring = Graph(NX.tetrahedral_graph()) + sage: tetra_spring = Graph(NX.tetrahedral_graph()) # optional - networkx sage: wheel = graphs.WheelGraph(4) sage: complete = graphs.CompleteGraph(4) - sage: g = [tetra_pos, tetra_spring, wheel, complete] + sage: g = [tetra_pos, tetra_spring, wheel, complete] # optional - networkx sage: j = [] - sage: for i in range(2): + sage: for i in range(2): # optional - networkx ....: n = [] ....: for m in range(2): ....: n.append(g[i + m].plot(vertex_size=50, vertex_labels=False)) ....: j.append(n) - sage: G = graphics_array(j) - sage: G.show() # long time + sage: G = graphics_array(j) # optional - networkx + sage: G.show() # long time # optional - networkx """ edges = [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)] pos = {0: (0, 0), diff --git a/src/sage/graphs/generators/smallgraphs.py b/src/sage/graphs/generators/smallgraphs.py index 00ce30403bb..8a4a72b13f7 100644 --- a/src/sage/graphs/generators/smallgraphs.py +++ b/src/sage/graphs/generators/smallgraphs.py @@ -1804,9 +1804,9 @@ def ChvatalGraph(): TESTS:: - sage: import networkx + sage: import networkx # optional - networkx sage: G = graphs.ChvatalGraph() - sage: G.is_isomorphic(Graph(networkx.chvatal_graph())) + sage: G.is_isomorphic(Graph(networkx.chvatal_graph())) # optional - networkx True """ edges = {0: [1, 4, 6, 9], 1: [2, 5, 7], 2: [3, 6, 8], 3: [4, 7, 9], @@ -2835,9 +2835,9 @@ def HeawoodGraph(): TESTS:: - sage: import networkx + sage: import networkx # optional - networkx sage: G = graphs.HeawoodGraph() - sage: G.is_isomorphic(Graph(networkx.heawood_graph())) + sage: G.is_isomorphic(Graph(networkx.heawood_graph())) # optional - networkx True """ edges = {0: [1, 5, 13], 1: [2, 10], 2: [3, 7], 3: [4, 12], 4: [5, 9], @@ -3294,9 +3294,9 @@ def KrackhardtKiteGraph(): TESTS:: - sage: import networkx + sage: import networkx # optional - networkx sage: G = graphs.KrackhardtKiteGraph() - sage: G.is_isomorphic(Graph(networkx.krackhardt_kite_graph())) + sage: G.is_isomorphic(Graph(networkx.krackhardt_kite_graph())) # optional - networkx True """ edges = {0: [1, 2, 3, 5], 1: [3, 4, 6], 2: [3, 5], 3: [4, 5, 6], diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 29c33406774..d46792f9e07 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -1371,14 +1371,14 @@ def export_to_file(self, filename, format=None, **kwds): sage: g = graphs.PetersenGraph() sage: filename = tmp_filename(ext=".pajek") sage: g.export_to_file(filename) - sage: import networkx - sage: G_networkx = networkx.read_pajek(filename) - sage: Graph(G_networkx).is_isomorphic(g) + sage: import networkx # optional - networkx + sage: G_networkx = networkx.read_pajek(filename) # optional - networkx + sage: Graph(G_networkx).is_isomorphic(g) # optional - networkx True sage: filename = tmp_filename(ext=".edgelist") sage: g.export_to_file(filename, data=False) - sage: h = Graph(networkx.read_edgelist(filename)) - sage: g.is_isomorphic(h) + sage: h = Graph(networkx.read_edgelist(filename)) # optional - networkx + sage: g.is_isomorphic(h) # optional - networkx True TESTS:: diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py index 266bfd09e9d..12657a226c3 100644 --- a/src/sage/graphs/graph.py +++ b/src/sage/graphs/graph.py @@ -112,10 +112,10 @@ :: - sage: import networkx - sage: K = networkx.complete_bipartite_graph(12,7) - sage: G = Graph(K) - sage: G.degree() + sage: import networkx # optional - networkx + sage: K = networkx.complete_bipartite_graph(12,7) # optional - networkx + sage: G = Graph(K) # optional - networkx + sage: G.degree() # optional - networkx [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 12, 12, 12, 12, 12, 12, 12] - graph6 or sparse6 format: @@ -800,16 +800,16 @@ class Graph(GenericGraph): #. A NetworkX MultiGraph:: - sage: import networkx - sage: g = networkx.MultiGraph({0:[1,2,3], 2:[4]}) - sage: Graph(g) + sage: import networkx # optional - networkx + sage: g = networkx.MultiGraph({0:[1,2,3], 2:[4]}) # optional - networkx + sage: Graph(g) # optional - networkx Multi-graph on 5 vertices #. A NetworkX graph:: - sage: import networkx - sage: g = networkx.Graph({0:[1,2,3], 2:[4]}) - sage: DiGraph(g) + sage: import networkx # optional - networkx + sage: g = networkx.Graph({0:[1,2,3], 2:[4]}) # optional - networkx + sage: DiGraph(g) # optional - networkx Digraph on 5 vertices #. An igraph Graph (see also diff --git a/src/sage/graphs/graph_generators_pyx.pyx b/src/sage/graphs/graph_generators_pyx.pyx index 8b5b68b7d26..716f4e5975a 100644 --- a/src/sage/graphs/graph_generators_pyx.pyx +++ b/src/sage/graphs/graph_generators_pyx.pyx @@ -55,8 +55,8 @@ def RandomGNP(n, p, bint directed=False, bint loops=False, seed=None): TESTS:: - sage: from numpy import mean - sage: abs(mean([RandomGNP(200, .2).density() for i in range(30)]) - .2) < .001 + sage: from numpy import mean # optional - numpy + sage: abs(mean([RandomGNP(200, .2).density() for i in range(30)]) - .2) < .001 # optional - numpy True sage: RandomGNP(150, .2, loops=True) Traceback (most recent call last): diff --git a/src/sage/graphs/graph_input.py b/src/sage/graphs/graph_input.py index fe1de72dcc5..1c952fcceae 100644 --- a/src/sage/graphs/graph_input.py +++ b/src/sage/graphs/graph_input.py @@ -614,42 +614,42 @@ def from_networkx_graph(G, gnx, weighted=None, loops=None, multiedges=None, Feeding a :class:`Graph` with a NetworkX ``Graph``:: sage: from sage.graphs.graph_input import from_networkx_graph - sage: import networkx + sage: import networkx # optional - networkx sage: G = Graph() - sage: _ = gnx = networkx.Graph() - sage: _ = gnx.add_edge(0, 1) - sage: _ = gnx.add_edge(1, 2) - sage: from_networkx_graph(G, gnx) - sage: G.edges(sort=True, labels=False) + sage: _ = gnx = networkx.Graph() # optional - networkx + sage: _ = gnx.add_edge(0, 1) # optional - networkx + sage: _ = gnx.add_edge(1, 2) # optional - networkx + sage: from_networkx_graph(G, gnx) # optional - networkx + sage: G.edges(sort=True, labels=False) # optional - networkx [(0, 1), (1, 2)] Feeding a :class:`Graph` with a NetworkX ``MultiGraph``:: sage: G = Graph() - sage: gnx = networkx.MultiGraph() - sage: _ = gnx.add_edge(0, 1) - sage: _ = gnx.add_edge(0, 1) - sage: from_networkx_graph(G, gnx) - sage: G.edges(sort=True, labels=False) + sage: gnx = networkx.MultiGraph() # optional - networkx + sage: _ = gnx.add_edge(0, 1) # optional - networkx + sage: _ = gnx.add_edge(0, 1) # optional - networkx + sage: from_networkx_graph(G, gnx) # optional - networkx + sage: G.edges(sort=True, labels=False) # optional - networkx [(0, 1), (0, 1)] sage: G = Graph() - sage: from_networkx_graph(G, gnx, multiedges=False) - sage: G.edges(sort=True, labels=False) + sage: from_networkx_graph(G, gnx, multiedges=False) # optional - networkx + sage: G.edges(sort=True, labels=False) # optional - networkx [(0, 1)] When feeding a :class:`Graph` `G` with a NetworkX ``DiGraph`` `D`, `G` has one edge `(u, v)` whenever `D` has arc `(u, v)` or `(v, u)` or both:: sage: G = Graph() - sage: D = networkx.DiGraph() - sage: _ = D.add_edge(0, 1) - sage: from_networkx_graph(G, D) - sage: G.edges(sort=True, labels=False) + sage: D = networkx.DiGraph() # optional - networkx + sage: _ = D.add_edge(0, 1) # optional - networkx + sage: from_networkx_graph(G, D) # optional - networkx + sage: G.edges(sort=True, labels=False) # optional - networkx [(0, 1)] sage: G = Graph() - sage: _ = D.add_edge(1, 0) - sage: from_networkx_graph(G, D) - sage: G.edges(sort=True, labels=False) + sage: _ = D.add_edge(1, 0) # optional - networkx + sage: from_networkx_graph(G, D) # optional - networkx + sage: G.edges(sort=True, labels=False) # optional - networkx [(0, 1)] When feeding a :class:`Graph` `G` with a NetworkX ``MultiDiGraph`` `D`, the @@ -657,50 +657,50 @@ def from_networkx_graph(G, gnx, weighted=None, loops=None, multiedges=None, of arcs `(u, v)` and the number of arcs `(v, u)` in D`:: sage: G = Graph() - sage: D = networkx.MultiDiGraph() - sage: _ = D.add_edge(0, 1) - sage: _ = D.add_edge(1, 0) - sage: _ = D.add_edge(1, 0) - sage: D.edges() + sage: D = networkx.MultiDiGraph() # optional - networkx + sage: _ = D.add_edge(0, 1) # optional - networkx + sage: _ = D.add_edge(1, 0) # optional - networkx + sage: _ = D.add_edge(1, 0) # optional - networkx + sage: D.edges() # optional - networkx OutMultiEdgeDataView([(0, 1), (1, 0), (1, 0)]) - sage: from_networkx_graph(G, D) - sage: G.edges(sort=True, labels=False) + sage: from_networkx_graph(G, D) # optional - networkx + sage: G.edges(sort=True, labels=False) # optional - networkx [(0, 1), (0, 1)] Feeding a :class:`DiGraph` with a NetworkX ``DiGraph``:: sage: from sage.graphs.graph_input import from_networkx_graph - sage: import networkx + sage: import networkx # optional - networkx sage: G = DiGraph() - sage: _ = gnx = networkx.DiGraph() - sage: _ = gnx.add_edge(0, 1) - sage: _ = gnx.add_edge(1, 2) - sage: from_networkx_graph(G, gnx) - sage: G.edges(sort=True, labels=False) + sage: _ = gnx = networkx.DiGraph() # optional - networkx + sage: _ = gnx.add_edge(0, 1) # optional - networkx + sage: _ = gnx.add_edge(1, 2) # optional - networkx + sage: from_networkx_graph(G, gnx) # optional - networkx + sage: G.edges(sort=True, labels=False) # optional - networkx [(0, 1), (1, 2)] Feeding a :class:`DiGraph` with a NetworkX ``MultiDiGraph``:: sage: G = DiGraph() - sage: gnx = networkx.MultiDiGraph() - sage: _ = gnx.add_edge(0, 1) - sage: _ = gnx.add_edge(0, 1) - sage: from_networkx_graph(G, gnx) - sage: G.edges(sort=True, labels=False) + sage: gnx = networkx.MultiDiGraph() # optional - networkx + sage: _ = gnx.add_edge(0, 1) # optional - networkx + sage: _ = gnx.add_edge(0, 1) # optional - networkx + sage: from_networkx_graph(G, gnx) # optional - networkx + sage: G.edges(sort=True, labels=False) # optional - networkx [(0, 1), (0, 1)] sage: G = DiGraph() - sage: from_networkx_graph(G, gnx, multiedges=False) - sage: G.edges(sort=True, labels=False) + sage: from_networkx_graph(G, gnx, multiedges=False) # optional - networkx + sage: G.edges(sort=True, labels=False) # optional - networkx [(0, 1)] When feeding a :class:`DiGraph` `G` with a NetworkX ``Graph`` `H`, `G` has both arcs `(u, v)` and `(v, u)` if `G` has edge `(u, v)`:: sage: G = DiGraph() - sage: H = networkx.Graph() - sage: _ = H.add_edge(0, 1) - sage: from_networkx_graph(G, H) - sage: G.edges(labels=False, sort=True) + sage: H = networkx.Graph() # optional - networkx + sage: _ = H.add_edge(0, 1) # optional - networkx + sage: from_networkx_graph(G, H) # optional - networkx + sage: G.edges(labels=False, sort=True) # optional - networkx [(0, 1), (1, 0)] When feeding a :class:`DiGraph` `G` with a NetworkX ``MultiGraph`` `H`, `G` @@ -708,18 +708,18 @@ def from_networkx_graph(G, gnx, weighted=None, loops=None, multiedges=None, unless parameter ``multiedges`` is set to ``False``:: sage: G = DiGraph() - sage: H = networkx.MultiGraph() - sage: _ = H.add_edge(0, 1) - sage: _ = H.add_edge(0, 1) - sage: _ = H.add_edge(0, 1) - sage: H.edges() + sage: H = networkx.MultiGraph() # optional - networkx + sage: _ = H.add_edge(0, 1) # optional - networkx + sage: _ = H.add_edge(0, 1) # optional - networkx + sage: _ = H.add_edge(0, 1) # optional - networkx + sage: H.edges() # optional - networkx MultiEdgeDataView([(0, 1), (0, 1), (0, 1)]) - sage: from_networkx_graph(G, H) - sage: G.edges(labels=False, sort=True) + sage: from_networkx_graph(G, H) # optional - networkx + sage: G.edges(labels=False, sort=True) # optional - networkx [(0, 1), (0, 1), (0, 1), (1, 0), (1, 0), (1, 0)] sage: G = DiGraph() - sage: from_networkx_graph(G, H, multiedges=False) - sage: G.edges(labels=False, sort=True) + sage: from_networkx_graph(G, H, multiedges=False) # optional - networkx + sage: G.edges(labels=False, sort=True) # optional - networkx [(0, 1), (1, 0)] TESTS: @@ -736,7 +736,7 @@ def from_networkx_graph(G, gnx, weighted=None, loops=None, multiedges=None, ``DiGraph`` or ``MultiDiGraph``:: sage: from sage.graphs.graph_input import from_networkx_graph - sage: from_networkx_graph(Graph(), "bar") + sage: from_networkx_graph(Graph(), "bar") # optional - networkx Traceback (most recent call last): ... ValueError: the second parameter must be a NetworkX (Multi)(Di)Graph diff --git a/src/sage/graphs/planarity.pyx b/src/sage/graphs/planarity.pyx index b5a78f0bf14..839039a2bde 100644 --- a/src/sage/graphs/planarity.pyx +++ b/src/sage/graphs/planarity.pyx @@ -72,17 +72,17 @@ def is_planar(g, kuratowski=False, set_pos=False, set_embedding=False, circular= vertices. In fact, to try to track down a segfault, we do it twice. :: - sage: import networkx.generators.atlas # long time - sage: atlas_graphs = [Graph(i) for i in networkx.generators.atlas.graph_atlas_g()] # long time - sage: a = [i for i in [1..1252] if atlas_graphs[i].is_planar()] # long time - sage: b = [i for i in [1..1252] if atlas_graphs[i].is_planar()] # long time - sage: a == b # long time + sage: import networkx.generators.atlas # long time # optional - networkx + sage: atlas_graphs = [Graph(i) for i in networkx.generators.atlas.graph_atlas_g()] # long time # optional - networkx + sage: a = [i for i in [1..1252] if atlas_graphs[i].is_planar()] # long time # optional - networkx + sage: b = [i for i in [1..1252] if atlas_graphs[i].is_planar()] # long time # optional - networkx + sage: a == b # long time # optional - networkx True There were some problems with ``set_pos`` stability in the past, so let's check if this runs without exception:: - sage: for i, g in enumerate(atlas_graphs): # long time + sage: for i, g in enumerate(atlas_graphs): # long time # optional - networkx ....: if (not g.is_connected() or i == 0): ....: continue ....: _ = g.is_planar(set_embedding=True, set_pos=True)