Skip to content

Commit a7f7365

Browse files
authored
Merge branch 'master' into mathics-5.0.0-more-adjustments
2 parents dd62dc6 + 701b6d4 commit a7f7365

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

pymathics/graph/__main__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def default_format(self, evaluation, form):
471471
def do_format(self, evaluation, form):
472472
return self
473473

474-
def get_sort_key(self, pattern_sort=False) -> list:
474+
def get_sort_key(self, pattern_sort=False) -> tuple:
475475
"""
476476
Returns a particular encoded list (which should be a tuple) that is used
477477
in ``Sort[]`` comparisons and in the ordering that occurs
@@ -516,6 +516,12 @@ def is_mixed_graph(self):
516516
def is_multigraph(self):
517517
return isinstance(self.G, (nx.MultiDiGraph, nx.MultiGraph))
518518

519+
def get_sort_key(self, pattern_sort=False):
520+
if pattern_sort:
521+
return super(Graph, self).get_sort_key(True)
522+
else:
523+
return (1, 3, Symbol("Pymathics`Graph"), tuple(), 2, len(self.pixels), hash(self))
524+
519525
@property
520526
def value(self):
521527
return self.G

pymathics/graph/generators.py

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

146146

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

0 commit comments

Comments
 (0)