Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
trac 22349: vertex sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpalmieri committed Jul 18, 2022
1 parent 68ea9dc commit 1ec4bdf
Show file tree
Hide file tree
Showing 97 changed files with 520 additions and 489 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ We begin by creating a graph with 4 vertices::

This graph has no edges yet::

sage: G.vertices()
sage: G.vertices(sort=True)
[0, 1, 2, 3]
sage: G.edges()
sage: G.edges(sort=True)
[]

Before we can add edges, we need to tell Sage that our graph can
Expand Down
16 changes: 8 additions & 8 deletions src/doc/en/thematic_tutorials/sandpile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Laplacian.

**Example.** (Continued.) ::

sage: S.vertices() # the ordering of the vertices
sage: S.vertices(sort=True) # the ordering of the vertices
[0, 1, 2, 3]
sage: S.laplacian()
[ 0 0 0 0]
Expand Down Expand Up @@ -883,9 +883,9 @@ first presented. This internal format is returned by ``dict()``::
Code for checking whether a given vertex is a sink::

sage: S = Sandpile({0:[], 1:[0, 3, 4], 2:[0, 3, 5], 3: [2, 5], 4: [1, 3], 5: [2, 3]},0)
sage: [S.distance(v,0) for v in S.vertices()] # 0 is a sink
sage: [S.distance(v,0) for v in S.vertices(sort=True)] # 0 is a sink
[0, 1, 1, 2, 2, 2]
sage: [S.distance(v,1) for v in S.vertices()] # 1 is not a sink
sage: [S.distance(v,1) for v in S.vertices(sort=True)] # 1 is not a sink
[+Infinity, 0, +Infinity, +Infinity, 1, +Infinity]

Methods
Expand Down Expand Up @@ -4609,7 +4609,7 @@ EXAMPLES::
sage: D = SandpileDivisor(S, [0,0,1,1])
sage: D.support()
[2, 3]
sage: S.vertices()
sage: S.vertices(sort=True)
[0, 1, 2, 3]

---
Expand Down Expand Up @@ -4654,7 +4654,7 @@ EXAMPLES::
{'a': 0, 'b': 1, 'c': 2}
sage: D.values()
[0, 1, 2]
sage: S.vertices()
sage: S.vertices(sort=True)
['a', 'b', 'c']


Expand Down Expand Up @@ -4715,9 +4715,9 @@ EXAMPLES::

sage: s = sandpiles.Cycle(4)
sage: D = SandpileDivisor(s,[2,0,0,0])
sage: [D.weierstrass_gap_seq(v,False) for v in s.vertices()]
sage: [D.weierstrass_gap_seq(v,False) for v in s.vertices(sort=True)]
[(1, 3), (1, 2), (1, 3), (1, 2)]
sage: [D.weierstrass_gap_seq(v) for v in s.vertices()]
sage: [D.weierstrass_gap_seq(v) for v in s.vertices(sort=True)]
[((1, 3), 1), ((1, 2), 0), ((1, 3), 1), ((1, 2), 0)]
sage: D.weierstrass_gap_seq() # gap sequence at sink vertex, 0
((1, 3), 1)
Expand Down Expand Up @@ -4786,7 +4786,7 @@ EXAMPLES::

sage: s = sandpiles.House()
sage: K = s.canonical_divisor()
sage: [K.weierstrass_rank_seq(v) for v in s.vertices()]
sage: [K.weierstrass_rank_seq(v) for v in s.vertices(sort=True)]
[(1, 0, -1), (1, 0, -1), (1, 0, -1), (1, 0, -1), (1, 0, 0, -1)]

---
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -2639,7 +2639,7 @@ def category_graph(categories = None):
EXAMPLES::
sage: G = sage.categories.category.category_graph(categories = [Groups()])
sage: G.vertices()
sage: G.vertices(sort=True)
['groups', 'inverse unital magmas', 'magmas', 'monoids', 'objects',
'semigroups', 'sets', 'sets with partial maps', 'unital magmas']
sage: G.plot()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/crystals.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ def digraph(self, subset=None, index_set=None):
sage: S = T.subcrystal(max_depth=3)
sage: G = T.digraph(subset=S); G
Digraph on 5 vertices
sage: sorted(G.vertices(), key=str)
sage: G.vertices(sort=True, key=str)
[(-Lambda[0] + 2*Lambda[1] - delta,),
(1/2*Lambda[0] + Lambda[1] - Lambda[2] - 1/2*delta, -1/2*Lambda[0] + Lambda[1] - 1/2*delta),
(1/2*Lambda[0] - Lambda[1] + Lambda[2] - 1/2*delta, -1/2*Lambda[0] + Lambda[1] - 1/2*delta),
Expand Down
4 changes: 2 additions & 2 deletions src/sage/categories/finite_coxeter_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ def coxeter_knuth_graph(self):
sage: W = WeylGroup(['A',4], prefix='s')
sage: w = W.from_reduced_word([1,2,1,3,2])
sage: D = w.coxeter_knuth_graph()
sage: D.vertices()
sage: D.vertices(sort=True)
[(1, 2, 1, 3, 2),
(1, 2, 3, 1, 2),
(2, 1, 2, 3, 2),
Expand All @@ -877,7 +877,7 @@ def coxeter_knuth_graph(self):
sage: w = W.from_reduced_word([1,3])
sage: D = w.coxeter_knuth_graph()
sage: D.vertices()
sage: D.vertices(sort=True)
[(1, 3), (3, 1)]
sage: D.edges()
[]
Expand Down
4 changes: 2 additions & 2 deletions src/sage/categories/regular_crystals.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def dual_equivalence_graph(self, X=None, index_set=None, directed=True):
sage: T = crystals.Tableaux(['A',4], shape=[3,1])
sage: G = T.dual_equivalence_graph(index_set=[1,2,3])
sage: G.vertices()
sage: G.vertices(sort=True)
[[[1, 3, 4], [2]], [[1, 2, 4], [3]], [[1, 2, 3], [4]]]
sage: G.edges()
[([[1, 3, 4], [2]], [[1, 2, 4], [3]], 2),
Expand All @@ -410,7 +410,7 @@ def dual_equivalence_graph(self, X=None, index_set=None, directed=True):
sage: sorted(G.edges())
[([[1, 2, 4], [3]], [[1, 2, 3], [4]], 3),
([[2, 4, 5], [3]], [[2, 3, 5], [4]], 3)]
sage: sorted(G.vertices())
sage: sorted(G.vertices(sort=True))
[[[1, 3, 4], [2]],
[[1, 2, 4], [3]],
[[2, 4, 5], [3]],
Expand Down
12 changes: 6 additions & 6 deletions src/sage/categories/semigroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def cayley_graph(self, side="right", simple=False, elements = None, generators =
Alternating group of order 5!/2 as a permutation group
sage: G = A5.cayley_graph()
sage: G.show3d(color_by_label=True, edge_size=0.01, edge_size2=0.02, vertex_size=0.03)
sage: G.show3d(vertex_size=0.03, edge_size=0.01, edge_size2=0.02, vertex_colors={(1,1,1):G.vertices()}, bgcolor=(0,0,0), color_by_label=True, xres=700, yres=700, iterations=200) # long time (less than a minute)
sage: G.show3d(vertex_size=0.03, edge_size=0.01, edge_size2=0.02, vertex_colors={(1,1,1):G.vertices(sort=True)}, bgcolor=(0,0,0), color_by_label=True, xres=700, yres=700, iterations=200) # long time (less than a minute)
sage: G.num_edges()
120
Expand Down Expand Up @@ -239,15 +239,15 @@ def cayley_graph(self, side="right", simple=False, elements = None, generators =
sage: S = FiniteSemigroups().example(alphabet=('a','b'))
sage: g = S.cayley_graph(simple=True)
sage: g.vertices()
sage: g.vertices(sort=True)
['a', 'ab', 'b', 'ba']
sage: g.edges()
[('a', 'ab', None), ('b', 'ba', None)]
::
sage: g = S.cayley_graph(side="left", simple=True)
sage: g.vertices()
sage: g.vertices(sort=True)
['a', 'ab', 'b', 'ba']
sage: g.edges()
[('a', 'ba', None), ('ab', 'ba', None), ('b', 'ab', None),
Expand All @@ -256,7 +256,7 @@ def cayley_graph(self, side="right", simple=False, elements = None, generators =
::
sage: g = S.cayley_graph(side="twosided", simple=True)
sage: g.vertices()
sage: g.vertices(sort=True)
['a', 'ab', 'b', 'ba']
sage: g.edges()
[('a', 'ab', None), ('a', 'ba', None), ('ab', 'ba', None),
Expand All @@ -265,14 +265,14 @@ def cayley_graph(self, side="right", simple=False, elements = None, generators =
::
sage: g = S.cayley_graph(side="twosided")
sage: g.vertices()
sage: g.vertices(sort=True)
['a', 'ab', 'b', 'ba']
sage: g.edges()
[('a', 'a', (0, 'left')), ('a', 'a', (0, 'right')), ('a', 'ab', (1, 'right')), ('a', 'ba', (1, 'left')), ('ab', 'ab', (0, 'left')), ('ab', 'ab', (0, 'right')), ('ab', 'ab', (1, 'right')), ('ab', 'ba', (1, 'left')), ('b', 'ab', (0, 'left')), ('b', 'b', (1, 'left')), ('b', 'b', (1, 'right')), ('b', 'ba', (0, 'right')), ('ba', 'ab', (0, 'left')), ('ba', 'ba', (0, 'right')), ('ba', 'ba', (1, 'left')), ('ba', 'ba', (1, 'right'))]
::
sage: s1 = SymmetricGroup(1); s = s1.cayley_graph(); s.vertices()
sage: s1 = SymmetricGroup(1); s = s1.cayley_graph(); s.vertices(sort=False)
[()]
TESTS::
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/weyl_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def quantum_bruhat_graph(self, index_set=()):
sage: g = W.quantum_bruhat_graph((1,3))
sage: g
Parabolic Quantum Bruhat Graph of Weyl Group of type ['A', 3] (as a matrix group acting on the ambient space) for nodes (1, 3): Digraph on 6 vertices
sage: g.vertices()
sage: g.vertices(sort=True)
[s2*s3*s1*s2, s3*s1*s2, s1*s2, s3*s2, s2, 1]
sage: g.edges()
[(s2*s3*s1*s2, s2, alpha[2]),
Expand Down
4 changes: 2 additions & 2 deletions src/sage/coding/linear_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2066,9 +2066,9 @@ def cosetGraph(self):
sage: M = matrix.identity(GF(3), 7)
sage: C = LinearCode(M)
sage: G = C.cosetGraph()
sage: G.vertices()
sage: G.vertices(sort=False)
[0]
sage: G.edges()
sage: G.edges(sort=False)
[]
"""
from sage.matrix.constructor import matrix
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/constellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ def braid_group_orbits(self):
sage: [x.profile() for x in O[2]]
[([2, 1], [2, 1], [3]), ([2, 1], [3], [2, 1]), ([3], [2, 1], [2, 1])]
"""
return [g.vertices() for g in self.braid_group_action()]
return [g.vertices(sort=True) for g in self.braid_group_action()]


class Constellations_p(UniqueRepresentation, Parent):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/crystals/alcove_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,7 @@ def compare_graphs(g1, g2, node1, node2):
sage: G1 = crystals.Tableaux(['A',3], shape=[1,1]).digraph()
sage: C = crystals.AlcovePaths(['A',3],[0,1,0])
sage: G2 = C.digraph()
sage: compare_graphs(G1, G2, C( () ), G2.vertices()[0])
sage: compare_graphs(G1, G2, C( () ), G2.vertices(sort=True)[0])
True
"""
for out_edge in g1.outgoing_edges( node1 ):
Expand Down Expand Up @@ -1974,7 +1974,7 @@ def _test_against_tableaux(R, N, k, clss=CrystalOfAlcovePaths):
if cc != ct:
print("FAIL: number of nodes differ.", cc, ct)
return
print(" Compare graphs: ", compare_graphs(G, H, C(()), H.vertices()[0]))
print(" Compare graphs: ", compare_graphs(G, H, C(()), H.vertices(sort=True)[0]))

def _test_with_lspaths_crystal(cartan_type, weight, depth=10):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/crystals/kirillov_reshetikhin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ class KR_type_A2(KirillovReshetikhinGenericCrystal):
sage: G = K.digraph()
sage: Gdual = Kdual.digraph()
sage: f = {0:2, 1:1, 2:0}
sage: Gnew = DiGraph(); Gnew.add_vertices(Gdual.vertices()); Gnew.add_edges([(u,v,f[i]) for (u,v,i) in Gdual.edges()])
sage: Gnew = DiGraph(); Gnew.add_vertices(Gdual.vertices(sort=True)); Gnew.add_edges([(u,v,f[i]) for (u,v,i) in Gdual.edges()])
sage: G.is_isomorphic(Gnew, edge_labels = True)
True
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/designs/twographs.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def twograph_descendant(G, v, name=None):
TESTS::
sage: T8 = graphs.CompleteGraph(8).line_graph()
sage: v = T8.vertices()[0]
sage: v = T8.vertices(sort=True)[0]
sage: twograph_descendant(T8, v)==T8.twograph().descendant(v)
True
sage: twograph_descendant(T8, v).is_strongly_regular(parameters=True)
Expand Down
12 changes: 6 additions & 6 deletions src/sage/combinat/diagram_algebras.py
Original file line number Diff line number Diff line change
Expand Up @@ -4531,9 +4531,9 @@ def to_graph(sp):
sage: g = da.to_graph( da.to_set_partition([[1,-2],[2,-1]])); g
Graph on 4 vertices
sage: g.vertices()
sage: g.vertices(sort=True)
[-2, -1, 1, 2]
sage: g.edges()
sage: g.edges(sort=True)
[(-2, 1, None), (-1, 2, None)]
"""
g = Graph()
Expand Down Expand Up @@ -4565,9 +4565,9 @@ def pair_to_graph(sp1, sp2):
sage: g = da.pair_to_graph( sp1, sp2 ); g
Graph on 8 vertices
sage: g.vertices()
sage: g.vertices(sort=True)
[(-2, 1), (-2, 2), (-1, 1), (-1, 2), (1, 1), (1, 2), (2, 1), (2, 2)]
sage: g.edges()
sage: g.edges(sort=True)
[((-2, 1), (1, 1), None), ((-2, 1), (2, 2), None),
((-2, 2), (1, 2), None), ((-1, 1), (1, 2), None),
((-1, 1), (2, 1), None), ((-1, 2), (2, 2), None)]
Expand All @@ -4579,9 +4579,9 @@ def pair_to_graph(sp1, sp2):
sage: g = da.pair_to_graph( sp3, sp4 ); g
Graph on 8 vertices
sage: g.vertices()
sage: g.vertices(sort=True)
[(-2, 1), (-2, 2), (-1, 1), (-1, 2), (1, 1), (1, 2), (2, 1), (2, 2)]
sage: g.edges()
sage: g.edges(sort=True)
[((-2, 1), (2, 2), None), ((-1, 1), (1, 1), None),
((-1, 1), (1, 2), None)]
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/finite_state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -8684,7 +8684,7 @@ def final_components(self):
DG = self.digraph()
condensation = DG.strongly_connected_components_digraph()
return [self.induced_sub_finite_state_machine([self.state(_) for _ in component])
for component in condensation.vertices()
for component in condensation.vertices(sort=True)
if condensation.out_degree(component) == 0]


Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -5260,10 +5260,10 @@ def dual_equivalence_graph(self, directed=False, coloring=None):
TESTS::

sage: G = Partition([1]).dual_equivalence_graph()
sage: G.vertices()
sage: G.vertices(sort=False)
[[[1]]]
sage: G = Partition([]).dual_equivalence_graph()
sage: G.vertices()
sage: G.vertices(sort=False)
[[]]

sage: P = Partition([3,1,1])
Expand Down
12 changes: 6 additions & 6 deletions src/sage/combinat/partition_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -1794,9 +1794,9 @@ def to_graph(sp):
sage: g = pa.to_graph( pa.to_set_partition([[1,-2],[2,-1]])); g
Graph on 4 vertices

sage: g.vertices() #random
sage: g.vertices(sort=False) #random
[1, 2, -2, -1]
sage: g.edges() #random
sage: g.edges(sort=False) #random
[(1, -2, None), (2, -1, None)]
"""
g = Graph()
Expand Down Expand Up @@ -1831,9 +1831,9 @@ def pair_to_graph(sp1, sp2):

::

sage: g.vertices() #random
sage: g.vertices(sort=False) #random
[(1, 2), (-1, 1), (-2, 2), (-1, 2), (-2, 1), (2, 1), (2, 2), (1, 1)]
sage: g.edges() #random
sage: g.edges(sort=False) #random
[((1, 2), (-1, 1), None),
((1, 2), (-2, 2), None),
((-1, 1), (2, 1), None),
Expand All @@ -1848,9 +1848,9 @@ def pair_to_graph(sp1, sp2):
sage: g = pa.pair_to_graph( sp3, sp4 ); g
Graph on 8 vertices

sage: g.vertices()
sage: g.vertices(sort=True)
[(-2, 1), (-2, 2), (-1, 1), (-1, 2), (1, 1), (1, 2), (2, 1), (2, 2)]
sage: g.edges()
sage: g.edges(sort=True)
[((-2, 1), (2, 2), None), ((-1, 1), (1, 1), None),
((-1, 1), (1, 2), None)]
"""
Expand Down
10 changes: 6 additions & 4 deletions src/sage/combinat/posets/hasse_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,8 @@ def are_incomparable(self, i, j):
sage: H = P._hasse_diagram
sage: H.are_incomparable(1,2)
True
sage: [ (i,j) for i in H.vertices() for j in H.vertices() if H.are_incomparable(i,j)]
sage: V = H.vertices(sort=True)
sage: [ (i,j) for i in V for j in V if H.are_incomparable(i,j)]
[(1, 2), (1, 3), (2, 1), (3, 1)]
"""
if i == j:
Expand All @@ -2249,7 +2250,8 @@ def are_comparable(self, i, j):
sage: H = P._hasse_diagram
sage: H.are_comparable(1,2)
False
sage: [ (i,j) for i in H.vertices() for j in H.vertices() if H.are_comparable(i,j)]
sage: V = H.vertices(sort=True)
sage: [ (i,j) for i in V for j in V if H.are_comparable(i,j)]
[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 0), (1, 1), (1, 4), (2, 0), (2, 2), (2, 3), (2, 4), (3, 0), (3, 2), (3, 3), (3, 4), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4)]
"""
if i == j:
Expand Down Expand Up @@ -2291,7 +2293,7 @@ def antichains(self, element_class=list):
sage: TestSuite(A).run()
"""
from sage.combinat.subsets_pairwise import PairwiseCompatibleSubsets
return PairwiseCompatibleSubsets(self.vertices(),
return PairwiseCompatibleSubsets(self.vertices(sort=True),
self.are_incomparable,
element_class=element_class)

Expand Down Expand Up @@ -2450,7 +2452,7 @@ def diamonds(self):
"""
diamonds = []
all_diamonds_completed = True
for w in self.vertices():
for w in self.vertices(sort=True):
covers = self.neighbors_out(w)
for i, x in enumerate(covers):
for y in covers[i + 1:]:
Expand Down
Loading

0 comments on commit 1ec4bdf

Please sign in to comment.