Skip to content

Commit 12ba8c8

Browse files
committed
Handle directed edge case?
1 parent b615d47 commit 12ba8c8

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

pymathics/graph/generators.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ def apply(self, m1, m2, expression, evaluation, options):
143143
return g
144144

145145

146-
# Oddly, networkX doesn't allow the directed case.
146+
# This code will be in the 2.6 release of networkx.
147+
# See https://github.com/networkx/networkx/pull/4461
147148
def binomial_tree(n, create_using=None):
148149
"""Returns the Binomial Tree of order n.
149150
@@ -161,11 +162,20 @@ def binomial_tree(n, create_using=None):
161162
G : NetworkX graph
162163
A binomial tree of $2^n$ vertices and $2^n - 1$ edges.
163164
165+
create_using : NetworkX graph constructor, optional (default=nx.Graph)
166+
Graph type to create. If graph instance, then cleared before populated.
167+
168+
Returns
169+
-------
170+
G : NetworkX graph
171+
A binomial tree of $2^n$ nodes and $2^n - 1$ edges.
172+
164173
"""
165-
G = nx.empty_graph(1, create_using=create_using)
174+
G = nx.empty_graph(1, create_using)
166175
N = 1
167176
for i in range(n):
168-
edges = [(u + N, v + N) for (u, v) in G.edges]
177+
# Use G.edges() to ensure 2-tuples. G.edges is 3-tuple for MultiGraph
178+
edges = [(u + N, v + N) for (u, v) in G.edges()]
169179
G.add_edges_from(edges)
170180
G.add_edge(0, N)
171181
N *= 2

0 commit comments

Comments
 (0)