rm CondaPkg environment

This commit is contained in:
ton
2023-04-06 13:53:47 +07:00
parent 0a57ed7884
commit c43d949309
3329 changed files with 5725 additions and 447022 deletions

View File

@@ -403,9 +403,38 @@ def cycle_graph(n, create_using=None):
def dorogovtsev_goltsev_mendes_graph(n, create_using=None):
"""Returns the hierarchically constructed Dorogovtsev-Goltsev-Mendes graph.
n is the generation.
See: arXiv:/cond-mat/0112143 by Dorogovtsev, Goltsev and Mendes.
The Dorogovtsev-Goltsev-Mendes [1]_ procedure produces a scale-free graph
deterministically with the following properties for a given `n`:
- Total number of nodes = ``3 * (3**n + 1) / 2``
- Total number of edges = ``3 ** (n + 1)``
Parameters
----------
n : integer
The generation number.
create_using : NetworkX Graph, optional
Graph type to be returned. Directed graphs and multi graphs are not
supported.
Returns
-------
G : NetworkX Graph
Examples
--------
>>> G = nx.dorogovtsev_goltsev_mendes_graph(3)
>>> G.number_of_nodes()
15
>>> G.number_of_edges()
27
>>> nx.is_planar(G)
True
References
----------
.. [1] Dorogotsev S.N., Goltsev A.V., and Mendes J.F.F "Pseudofractal
Scale-free Web". arXiv:cond-mat/0112143
"""
G = empty_graph(0, create_using)
if G.is_directed():
@@ -507,7 +536,7 @@ def empty_graph(n=0, create_using=None, default=Graph):
"""
if create_using is None:
G = default()
elif type(create_using) is type:
elif isinstance(create_using, type):
G = create_using()
elif not hasattr(create_using, "adj"):
raise TypeError("create_using is not a valid NetworkX graph type or instance")
@@ -802,7 +831,7 @@ def complete_multipartite_graph(*subset_sizes):
# add nodes with subset attribute
# while checking that ints are not mixed with iterables
try:
for (i, subset) in enumerate(subsets):
for i, subset in enumerate(subsets):
G.add_nodes_from(subset, subset=i)
except TypeError as err:
raise NetworkXError("Arguments must be all ints or all iterables") from err

View File

@@ -159,7 +159,7 @@ def relaxed_caveman_graph(l, k, p, seed=None):
"""
G = nx.caveman_graph(l, k)
nodes = list(G)
for (u, v) in G.edges():
for u, v in G.edges():
if seed.random() < p: # rewire the edge
x = seed.choice(nodes)
if G.has_edge(u, x):

View File

@@ -94,7 +94,7 @@ def gnr_graph(n, p, create_using=None, seed=None):
The GNR graph is built by adding nodes one at a time with a link to one
previously added node. The previous target node is chosen uniformly at
random. With probabiliy `p` the link is instead "redirected" to the
random. With probability `p` the link is instead "redirected" to the
successor node of the target.
The graph is always a (directed) tree.

View File

@@ -70,8 +70,8 @@ def margulis_gabber_galil_graph(n, create_using=None):
msg = "`create_using` must be an undirected multigraph."
raise nx.NetworkXError(msg)
for (x, y) in itertools.product(range(n), repeat=2):
for (u, v) in (
for x, y in itertools.product(range(n), repeat=2):
for u, v in (
((x + 2 * y) % n, y),
((x + (2 * y + 1)) % n, y),
(x, (y + 2 * x) % n),
@@ -146,22 +146,22 @@ def chordal_cycle_graph(p, create_using=None):
def paley_graph(p, create_using=None):
"""Returns the Paley (p-1)/2-regular graph on p nodes.
r"""Returns the Paley $\frac{(p-1)}{2}$ -regular graph on $p$ nodes.
The returned graph is a graph on Z/pZ with edges between x and y
if and only if x-y is a nonzero square in Z/pZ.
The returned graph is a graph on $\mathbb{Z}/p\mathbb{Z}$ with edges between $x$ and $y$
if and only if $x-y$ is a nonzero square in $\mathbb{Z}/p\mathbb{Z}$.
If p = 1 mod 4, -1 is a square in Z/pZ and therefore x-y is a square if and
only if y-x is also a square, i.e the edges in the Paley graph are symmetric.
If $p \equiv 1 \pmod 4$, $-1$ is a square in $\mathbb{Z}/p\mathbb{Z}$ and therefore $x-y$ is a square if and
only if $y-x$ is also a square, i.e the edges in the Paley graph are symmetric.
If p = 3 mod 4, -1 is not a square in Z/pZ and therefore either x-y or y-x
is a square in Z/pZ but not both.
If $p \equiv 3 \pmod 4$, $-1$ is not a square in $\mathbb{Z}/p\mathbb{Z}$ and therefore either $x-y$ or $y-x$
is a square in $\mathbb{Z}/p\mathbb{Z}$ but not both.
Note that a more general definition of Paley graphs extends this construction
to graphs over q=p^n vertices, by using the finite field F_q instead of Z/pZ.
to graphs over $q=p^n$ vertices, by using the finite field $F_q$ instead of $\mathbb{Z}/p\mathbb{Z}$.
This construction requires to compute squares in general finite fields and is
not what is implemented here (i.e paley_graph(25) does not return the true
Paley graph associated with 5^2).
not what is implemented here (i.e `paley_graph(25)` does not return the true
Paley graph associated with $5^2$).
Parameters
----------

View File

@@ -376,7 +376,7 @@ class AS_graph_generator:
self.nodes = {"T": set(), "M": set(), "CP": set(), "C": set()}
self.t_graph()
self.nodes["T"] = set(list(self.G.nodes()))
self.nodes["T"] = set(self.G.nodes())
i = len(self.nodes["T"])
for _ in range(self.n_m):

View File

@@ -227,13 +227,11 @@ def joint_degree_graph(joint_degrees, seed=None):
# for each pair
for k in joint_degrees:
for l in joint_degrees[k]:
# n_edges_add is the number of edges to add for the
# degree pair (k,l)
n_edges_add = joint_degrees[k][l]
if (n_edges_add > 0) and (k >= l):
# number of nodes with degree k and l
k_size = degree_count[k]
l_size = degree_count[l]
@@ -253,14 +251,12 @@ def joint_degree_graph(joint_degrees, seed=None):
n_edges_add = joint_degrees[k][l] // 2
while n_edges_add > 0:
# randomly pick nodes v and w that have degrees k and l
v = k_nodes[seed.randrange(k_size)]
w = l_nodes[seed.randrange(l_size)]
# if nodes v and w are disconnected then attempt to connect
if not G.has_edge(v, w) and (v != w):
# if node v has no free stubs then do neighbor switch
if h_node_residual[v] == 0:
_neighbor_switch(G, v, k_unsat, h_node_residual)
@@ -351,13 +347,7 @@ def is_valid_directed_joint_degree(in_degrees, out_degrees, nkk):
if val + forbidden.get((k, l), 0) > V[(k, 1)] * V[(l, 0)]:
return False
for s in S:
if not S[s] / s[0] == V[s]: # condition 2
return False
# if all conditions abive have been satisfied then the input nkk is
# realizable as a simple graph.
return True
return all(S[s] / s[0] == V[s] for s in S)
def _directed_neighbor_switch(

View File

@@ -243,7 +243,7 @@ def inverse_line_graph(G):
Notes
-----
This is an implementation of the Roussopoulos algorithm.
This is an implementation of the Roussopoulos algorithm[1]_.
If G consists of multiple components, then the algorithm doesn't work.
You should invert every component separately:
@@ -259,8 +259,9 @@ def inverse_line_graph(G):
References
----------
* Roussopolous, N, "A max {m, n} algorithm for determining the graph H from
its line graph G", Information Processing Letters 2, (1973), 108--112.
.. [1] Roussopoulos, N.D. , "A max {m, n} algorithm for determining the graph H from
its line graph G", Information Processing Letters 2, (1973), 108--112, ISSN 0020-0190,
`DOI link <https://doi.org/10.1016/0020-0190(73)90029-X>`_
"""
if G.number_of_nodes() == 0:
@@ -357,10 +358,7 @@ def _odd_triangle(G, T):
for v in G[t]:
if v not in T:
T_neighbors[v] += 1
for v in T_neighbors:
if T_neighbors[v] in [1, 3]:
return True
return False
return any(T_neighbors[v] in [1, 3] for v in T_neighbors)
def _find_partition(G, starting_cell):

View File

@@ -343,7 +343,7 @@ def newman_watts_strogatz_graph(n, k, p, seed=None):
# for each edge u-v, with probability p, randomly select existing
# node w and add new edge u-w
e = list(G.edges())
for (u, v) in e:
for u, v in e:
if seed.random() < p:
w = seed.choice(nlist)
# no self-loops and reject if edge u-w exists
@@ -487,6 +487,8 @@ def connected_watts_strogatz_graph(n, k, p, tries=100, seed=None):
def random_regular_graph(d, n, seed=None):
r"""Returns a random $d$-regular graph on $n$ nodes.
A regular graph is a graph where each node has the same number of neighbors.
The resulting graph has no self-loops or parallel edges.
Parameters
@@ -518,7 +520,7 @@ def random_regular_graph(d, n, seed=None):
.. [1] A. Steger and N. Wormald,
Generating random regular graphs quickly,
Probability and Computing 8 (1999), 377-396, 1999.
http://citeseer.ist.psu.edu/steger99generating.html
https://doi.org/10.1017/S0963548399003867
.. [2] Jeong Han Kim and Van H. Vu,
Generating random regular graphs,
@@ -1015,7 +1017,7 @@ def powerlaw_cluster_graph(n, m, p, seed=None):
neighborhood = [
nbr
for nbr in G.neighbors(target)
if not G.has_edge(source, nbr) and not nbr == source
if not G.has_edge(source, nbr) and nbr != source
]
if neighborhood: # if there is a neighbor without a link
nbr = seed.choice(neighborhood)
@@ -1065,7 +1067,7 @@ def random_lobster(n, p1, p2, seed=None):
If `p1` or `p2` parameters are >= 1 because the while loops would never finish.
"""
p1, p2 = abs(p1), abs(p2)
if any([p >= 1 for p in [p1, p2]]):
if any(p >= 1 for p in [p1, p2]):
raise nx.NetworkXError("Probability values for `p1` and `p2` must both be < 1.")
# a necessary ingredient in any self-respecting graph library
@@ -1114,7 +1116,7 @@ def random_shell_graph(constructor, seed=None):
intra_edges = []
nnodes = 0
# create gnm graphs for each shell
for (n, m, d) in constructor:
for n, m, d in constructor:
inter_edges = int(m * d)
intra_edges.append(m - inter_edges)
g = nx.convert_node_labels_to_integers(

View File

@@ -103,7 +103,7 @@ def LCF_graph(n, shift_list, repeats, create_using=None):
if G.is_directed():
raise NetworkXError("Directed Graph not supported")
G.name = "LCF_graph"
nodes = sorted(list(G))
nodes = sorted(G)
n_extra_edges = repeats * len(shift_list)
# edges are added n_extra_edges times

View File

@@ -6,6 +6,7 @@ Generators - Classic
Unit tests for various classic graph generators in generators/classic.py
"""
import itertools
import typing
import pytest
@@ -288,6 +289,15 @@ class TestGeneratorClassic:
assert not H.is_directed()
assert G is not H
# test for subclasses that also use typing.Protocol. See gh-6243
class Mixin(typing.Protocol):
pass
class MyGraph(Mixin, nx.DiGraph):
pass
G = nx.empty_graph(create_using=MyGraph)
def test_empty_graph(self):
G = nx.empty_graph()
assert nx.number_of_nodes(G) == 0
@@ -543,7 +553,7 @@ class TestGeneratorClassic:
assert v not in G[u]
assert G.nodes[u] == G.nodes[v]
# Across blocks, all vertices should be adjacent.
for (block1, block2) in itertools.combinations(blocks, 2):
for block1, block2 in itertools.combinations(blocks, 2):
for u, v in itertools.product(block1, block2):
assert v in G[u]
assert G.nodes[u] != G.nodes[v]

View File

@@ -87,19 +87,19 @@ class TestConfigurationModel:
nx.configuration_model([1, 2])
def test_directed_configuation_raise_unequal():
def test_directed_configuration_raise_unequal():
with pytest.raises(nx.NetworkXError):
zin = [5, 3, 3, 3, 3, 2, 2, 2, 1, 1]
zout = [5, 3, 3, 3, 3, 2, 2, 2, 1, 2]
nx.directed_configuration_model(zin, zout)
def test_directed_configuation_model():
def test_directed_configuration_model():
G = nx.directed_configuration_model([], [], seed=0)
assert len(G) == 0
def test_simple_directed_configuation_model():
def test_simple_directed_configuration_model():
G = nx.directed_configuration_model([1, 1], [1, 1], seed=0)
assert len(G) == 2
@@ -169,11 +169,11 @@ def test_directed_havel_hakimi():
p = 1.0 / r
for i in range(r):
G1 = nx.erdos_renyi_graph(n, p * (i + 1), None, True)
din1 = list(d for n, d in G1.in_degree())
dout1 = list(d for n, d in G1.out_degree())
din1 = [d for n, d in G1.in_degree()]
dout1 = [d for n, d in G1.out_degree()]
G2 = nx.directed_havel_hakimi_graph(din1, dout1)
din2 = list(d for n, d in G2.in_degree())
dout2 = list(d for n, d in G2.out_degree())
din2 = [d for n, d in G2.in_degree()]
dout2 = [d for n, d in G2.out_degree()]
assert sorted(din1) == sorted(din2)
assert sorted(dout1) == sorted(dout2)

View File

@@ -57,6 +57,41 @@ class TestGeneratorsDirected:
pytest.raises(ValueError, scale_free_graph, 100, beta=-0.3)
pytest.raises(ValueError, scale_free_graph, 100, gamma=-0.3)
def test_parameters(self):
G = nx.DiGraph()
G.add_node(0)
def kernel(x):
return x
assert nx.is_isomorphic(gn_graph(1), G)
assert nx.is_isomorphic(gn_graph(1, kernel=kernel), G)
assert nx.is_isomorphic(gnc_graph(1), G)
assert nx.is_isomorphic(gnr_graph(1, 0.5), G)
def test_scale_free_graph_create_using_with_initial_graph():
G = nx.MultiGraph()
with pytest.raises(
ValueError,
match="Cannot set both create_using and initial_graph. Set create_using=None.",
):
scale_free_graph(10, create_using=nx.Graph, initial_graph=G)
def test_scale_free_graph_negative_delta():
with pytest.raises(ValueError, match="delta_in must be >= 0."):
scale_free_graph(10, create_using=None, delta_in=-1)
with pytest.raises(ValueError, match="delta_out must be >= 0."):
scale_free_graph(10, create_using=None, delta_out=-1)
def test_non_numeric_ordering():
G = MultiDiGraph([("a", "b"), ("b", "c"), ("c", "a")])
s = scale_free_graph(3, initial_graph=G)
assert len(s) == 3
assert len(s.edges) == 3
@pytest.mark.parametrize("ig", (nx.Graph(), nx.DiGraph([(0, 1)])))
def test_scale_free_graph_initial_graph_kwarg(ig):
@@ -88,6 +123,10 @@ class TestRandomKOutGraph:
G = random_k_out_graph(n, k, alpha, self_loops=False)
assert nx.number_of_selfloops(G) == 0
def test_negative_alpha(self):
with pytest.raises(ValueError, match="alpha must be positive"):
random_k_out_graph(10, 3, -1)
class TestUniformRandomKOutGraph:
"""Unit tests for the
@@ -119,6 +158,11 @@ class TestUniformRandomKOutGraph:
G = random_uniform_k_out_graph(n, k, with_replacement=True)
assert G.is_multigraph()
assert all(d == k for v, d in G.out_degree())
n = 10
k = 9
G = random_uniform_k_out_graph(n, k, with_replacement=False, self_loops=False)
assert nx.number_of_selfloops(G) == 0
assert all(d == k for v, d in G.out_degree())
def test_without_replacement(self):
n = 10

View File

@@ -60,7 +60,7 @@ def test_paley_graph(p):
# If p = 1 mod 4, -1 is a square mod 4 and therefore the
# edge in the Paley graph are symmetric.
if p % 4 == 1:
for (u, v) in G.edges:
for u, v in G.edges:
assert (v, u) in G.edges

View File

@@ -101,6 +101,7 @@ class TestSoftRandomGeometricGraph:
generator.
"""
# Use the L1 metric.
def dist(x, y):
return sum(abs(a - b) for a, b in zip(x, y))
@@ -287,6 +288,7 @@ class TestThresholdedRandomGeometricGraph:
generator.
"""
# Use the L1 metric.
def dist(x, y):
return sum(abs(a - b) for a, b in zip(x, y))

View File

@@ -16,7 +16,7 @@ class TestHararyGraph:
def test_hnm_harary_graph(self):
# When d is even and r = 0, the hnm_harary_graph(n,m) is
# the circulant_graph(n, list(range(1,d/2+1)))
for (n, m) in [(5, 5), (6, 12), (7, 14)]:
for n, m in [(5, 5), (6, 12), (7, 14)]:
G1 = hnm_harary_graph(n, m)
d = 2 * m // n
G2 = nx.circulant_graph(n, list(range(1, d // 2 + 1)))
@@ -25,7 +25,7 @@ class TestHararyGraph:
# When d is even and r > 0, the hnm_harary_graph(n,m) is
# the circulant_graph(n, list(range(1,d/2+1)))
# with r edges added arbitrarily
for (n, m) in [(5, 7), (6, 13), (7, 16)]:
for n, m in [(5, 7), (6, 13), (7, 16)]:
G1 = hnm_harary_graph(n, m)
d = 2 * m // n
G2 = nx.circulant_graph(n, list(range(1, d // 2 + 1)))
@@ -34,7 +34,7 @@ class TestHararyGraph:
# When d is odd and n is even and r = 0, the hnm_harary_graph(n,m)
# is the circulant_graph(n, list(range(1,(d+1)/2) plus [n//2])
for (n, m) in [(6, 9), (8, 12), (10, 15)]:
for n, m in [(6, 9), (8, 12), (10, 15)]:
G1 = hnm_harary_graph(n, m)
d = 2 * m // n
L = list(range(1, (d + 1) // 2))
@@ -45,7 +45,7 @@ class TestHararyGraph:
# When d is odd and n is even and r > 0, the hnm_harary_graph(n,m)
# is the circulant_graph(n, list(range(1,(d+1)/2) plus [n//2])
# with r edges added arbitrarily
for (n, m) in [(6, 10), (8, 13), (10, 17)]:
for n, m in [(6, 10), (8, 13), (10, 17)]:
G1 = hnm_harary_graph(n, m)
d = 2 * m // n
L = list(range(1, (d + 1) // 2))
@@ -57,7 +57,7 @@ class TestHararyGraph:
# When d is odd and n is odd, the hnm_harary_graph(n,m) is
# the circulant_graph(n, list(range(1,(d+1)/2))
# with m - n*(d-1)/2 edges added arbitrarily
for (n, m) in [(5, 4), (7, 12), (9, 14)]:
for n, m in [(5, 4), (7, 12), (9, 14)]:
G1 = hnm_harary_graph(n, m)
d = 2 * m // n
L = list(range(1, (d + 1) // 2))
@@ -87,21 +87,21 @@ class TestHararyGraph:
def test_hkn_harary_graph(self):
# When k == 1, the hkn_harary_graph(k,n) is
# the path_graph(n)
for (k, n) in [(1, 6), (1, 7)]:
for k, n in [(1, 6), (1, 7)]:
G1 = hkn_harary_graph(k, n)
G2 = nx.path_graph(n)
assert is_isomorphic(G1, G2)
# When k is even, the hkn_harary_graph(k,n) is
# the circulant_graph(n, list(range(1,k/2+1)))
for (k, n) in [(2, 6), (2, 7), (4, 6), (4, 7)]:
for k, n in [(2, 6), (2, 7), (4, 6), (4, 7)]:
G1 = hkn_harary_graph(k, n)
G2 = nx.circulant_graph(n, list(range(1, k // 2 + 1)))
assert is_isomorphic(G1, G2)
# When k is odd and n is even, the hkn_harary_graph(k,n) is
# the circulant_graph(n, list(range(1,(k+1)/2)) plus [n/2])
for (k, n) in [(3, 6), (5, 8), (7, 10)]:
for k, n in [(3, 6), (5, 8), (7, 10)]:
G1 = hkn_harary_graph(k, n)
L = list(range(1, (k + 1) // 2))
L.append(n // 2)
@@ -111,7 +111,7 @@ class TestHararyGraph:
# When k is odd and n is odd, the hkn_harary_graph(k,n) is
# the circulant_graph(n, list(range(1,(k+1)/2))) with
# n//2+1 edges added between node i and node i+n//2+1
for (k, n) in [(3, 5), (5, 9), (7, 11)]:
for k, n in [(3, 5), (5, 9), (7, 11)]:
G1 = hkn_harary_graph(k, n)
G2 = nx.circulant_graph(n, list(range(1, (k + 1) // 2)))
eSet1 = set(G1.edges)

View File

@@ -80,7 +80,6 @@ def test_joint_degree_graph(ntimes=10):
def test_is_valid_directed_joint_degree():
in_degrees = [0, 1, 1, 2]
out_degrees = [1, 1, 1, 1]
nkk = {1: {1: 2, 2: 2}}
@@ -106,7 +105,6 @@ def test_is_valid_directed_joint_degree():
def test_directed_joint_degree_graph(n=15, m=100, ntimes=1000):
for _ in range(ntimes):
# generate gnm random graph and calculate its joint degree.
g = gnm_random_graph(n, m, None, directed=True)

View File

@@ -159,7 +159,7 @@ class TestTriangularLatticeGraph:
G = nx.triangular_lattice_graph(m, n)
N = (n + 1) // 2
assert len(G) == (m + 1) * (1 + N) - (n % 2) * ((m + 1) // 2)
for (i, j) in G.nodes():
for i, j in G.nodes():
nbrs = G[(i, j)]
if i < N:
assert (i + 1, j) in nbrs

View File

@@ -1,7 +1,7 @@
import pytest
import networkx as nx
import networkx.generators.line as line
from networkx.generators import line
from networkx.utils import edges_equal

View File

@@ -65,7 +65,7 @@ def test_gnp_generators_edge_probability(generator, p, directed):
edge_counts = [[0] * n for _ in range(n)]
for i in range(runs):
G = generator(n, p, directed=directed)
for (v, w) in G.edges:
for v, w in G.edges:
edge_counts[v][w] += 1
if not directed:
edge_counts[w][v] += 1
@@ -207,7 +207,6 @@ class TestGeneratorsRandom:
initial_graph = nx.complete_graph(10)
for seed in seeds:
# This should be BA with m = m1
BA1 = nx.barabasi_albert_graph(100, m1, seed)
DBA1 = nx.dual_barabasi_albert_graph(100, m1, m2, 1, seed)

View File

@@ -45,21 +45,21 @@ class TestGeneratorsSmall:
G = nx.chvatal_graph()
assert sorted(G) == list(range(12))
assert G.number_of_edges() == 24
assert list(d for n, d in G.degree()) == 12 * [4]
assert [d for n, d in G.degree()] == 12 * [4]
assert nx.diameter(G) == 2
assert nx.radius(G) == 2
G = nx.cubical_graph()
assert sorted(G) == list(range(8))
assert G.number_of_edges() == 12
assert list(d for n, d in G.degree()) == 8 * [3]
assert [d for n, d in G.degree()] == 8 * [3]
assert nx.diameter(G) == 3
assert nx.radius(G) == 3
G = nx.desargues_graph()
assert sorted(G) == list(range(20))
assert G.number_of_edges() == 30
assert list(d for n, d in G.degree()) == 20 * [3]
assert [d for n, d in G.degree()] == 20 * [3]
G = nx.diamond_graph()
assert sorted(G) == list(range(4))
@@ -70,28 +70,28 @@ class TestGeneratorsSmall:
G = nx.dodecahedral_graph()
assert sorted(G) == list(range(20))
assert G.number_of_edges() == 30
assert list(d for n, d in G.degree()) == 20 * [3]
assert [d for n, d in G.degree()] == 20 * [3]
assert nx.diameter(G) == 5
assert nx.radius(G) == 5
G = nx.frucht_graph()
assert sorted(G) == list(range(12))
assert G.number_of_edges() == 18
assert list(d for n, d in G.degree()) == 12 * [3]
assert [d for n, d in G.degree()] == 12 * [3]
assert nx.diameter(G) == 4
assert nx.radius(G) == 3
G = nx.heawood_graph()
assert sorted(G) == list(range(14))
assert G.number_of_edges() == 21
assert list(d for n, d in G.degree()) == 14 * [3]
assert [d for n, d in G.degree()] == 14 * [3]
assert nx.diameter(G) == 3
assert nx.radius(G) == 3
G = nx.hoffman_singleton_graph()
assert sorted(G) == list(range(50))
assert G.number_of_edges() == 175
assert list(d for n, d in G.degree()) == 50 * [7]
assert [d for n, d in G.degree()] == 50 * [7]
assert nx.diameter(G) == 2
assert nx.radius(G) == 2
@@ -112,7 +112,7 @@ class TestGeneratorsSmall:
G = nx.icosahedral_graph()
assert sorted(G) == list(range(12))
assert G.number_of_edges() == 30
assert list(d for n, d in G.degree()) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
assert [d for n, d in G.degree()] == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
assert nx.diameter(G) == 3
assert nx.radius(G) == 3
@@ -124,26 +124,26 @@ class TestGeneratorsSmall:
G = nx.moebius_kantor_graph()
assert sorted(G) == list(range(16))
assert G.number_of_edges() == 24
assert list(d for n, d in G.degree()) == 16 * [3]
assert [d for n, d in G.degree()] == 16 * [3]
assert nx.diameter(G) == 4
G = nx.octahedral_graph()
assert sorted(G) == list(range(6))
assert G.number_of_edges() == 12
assert list(d for n, d in G.degree()) == 6 * [4]
assert [d for n, d in G.degree()] == 6 * [4]
assert nx.diameter(G) == 2
assert nx.radius(G) == 2
G = nx.pappus_graph()
assert sorted(G) == list(range(18))
assert G.number_of_edges() == 27
assert list(d for n, d in G.degree()) == 18 * [3]
assert [d for n, d in G.degree()] == 18 * [3]
assert nx.diameter(G) == 4
G = nx.petersen_graph()
assert sorted(G) == list(range(10))
assert G.number_of_edges() == 15
assert list(d for n, d in G.degree()) == 10 * [3]
assert [d for n, d in G.degree()] == 10 * [3]
assert nx.diameter(G) == 2
assert nx.radius(G) == 2
@@ -155,24 +155,24 @@ class TestGeneratorsSmall:
G = nx.tetrahedral_graph()
assert sorted(G) == list(range(4))
assert G.number_of_edges() == 6
assert list(d for n, d in G.degree()) == [3, 3, 3, 3]
assert [d for n, d in G.degree()] == [3, 3, 3, 3]
assert nx.diameter(G) == 1
assert nx.radius(G) == 1
G = nx.truncated_cube_graph()
assert sorted(G) == list(range(24))
assert G.number_of_edges() == 36
assert list(d for n, d in G.degree()) == 24 * [3]
assert [d for n, d in G.degree()] == 24 * [3]
G = nx.truncated_tetrahedron_graph()
assert sorted(G) == list(range(12))
assert G.number_of_edges() == 18
assert list(d for n, d in G.degree()) == 12 * [3]
assert [d for n, d in G.degree()] == 12 * [3]
G = nx.tutte_graph()
assert sorted(G) == list(range(46))
assert G.number_of_edges() == 69
assert list(d for n, d in G.degree()) == 46 * [3]
assert [d for n, d in G.degree()] == 46 * [3]
# Test create_using with directed or multigraphs on small graphs
pytest.raises(nx.NetworkXError, nx.tutte_graph, create_using=nx.DiGraph)

View File

@@ -43,7 +43,7 @@ class TestStochasticGraph:
G = nx.MultiDiGraph()
G.add_edges_from([(0, 1), (0, 1), (0, 2), (0, 2)])
S = nx.stochastic_graph(G)
d = dict(weight=0.25)
d = {"weight": 0.25}
assert sorted(S.edges(data=True)) == [
(0, 1, d),
(0, 1, d),

View File

@@ -323,29 +323,29 @@ def random_tree(n, seed=None, create_using=None):
Examples
--------
>>> tree = nx.random_tree(n=10, seed=0)
>>> print(nx.forest_str(tree, sources=[0]))
>>> nx.write_network_text(tree, sources=[0])
╙── 0
├── 3
└── 4
├── 6
   ├── 1
   ├── 2
   └── 7
   └── 8
   └── 5
├── 1
├── 2
└── 7
└── 8
└── 5
└── 9
>>> tree = nx.random_tree(n=10, seed=0, create_using=nx.DiGraph)
>>> print(nx.forest_str(tree))
>>> nx.write_network_text(tree)
╙── 0
├─╼ 3
└─╼ 4
├─╼ 6
   ├─╼ 1
   ├─╼ 2
   └─╼ 7
   └─╼ 8
   └─╼ 5
├─╼ 1
├─╼ 2
└─╼ 7
└─╼ 8
└─╼ 5
└─╼ 9
"""
if n == 0: