Skip to content

Commit b567299

Browse files
author
Release Manager
committed
gh-39506: New algorithm for cuts of a Poset We replaced the algorithm for cuts by a more efficient one. ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. URL: #39506 Reported by: LudovicSchwob Reviewer(s): Frédéric Chapoton
2 parents 88672d7 + 753a3a4 commit b567299

File tree

1 file changed

+49
-15
lines changed

1 file changed

+49
-15
lines changed

src/sage/combinat/posets/posets.py

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8592,35 +8592,69 @@ def cuts(self):
85928592
A cut is a subset `A` of ``self`` such that the set of lower
85938593
bounds of the set of upper bounds of `A` is exactly `A`.
85948594
8595-
The cuts are computed here using the maximal independent sets in the
8596-
auxiliary graph defined as `P \times [0,1]` with an edge
8597-
from `(x, 0)` to `(y, 1)` if
8598-
and only if `x \not\geq_P y`. See the end of section 4 in [JRJ94]_.
8595+
The cuts are computed as the smallest family of subsets of P containing its
8596+
principal order filters, the whole set P and which is closed by intersection.
85998597
86008598
EXAMPLES::
86018599
86028600
sage: P = posets.AntichainPoset(3)
86038601
sage: Pc = P.cuts()
86048602
sage: Pc # random
8605-
[frozenset({0}),
8603+
[frozenset({2}),
8604+
frozenset({1}),
8605+
frozenset({0}),
86068606
frozenset(),
8607-
frozenset({0, 1, 2}),
8608-
frozenset({2}),
8609-
frozenset({1})]
8607+
frozenset({0, 1, 2})]
86108608
sage: sorted(list(c) for c in Pc)
86118609
[[], [0], [0, 1, 2], [1], [2]]
86128610
8611+
TESTS::
8612+
8613+
sage: P = Poset()
8614+
sage: P.cuts()
8615+
[frozenset()]
8616+
sage: P = Poset({3: [4, 5, 7], 1: [2, 4, 6], 4: [], 0: [2, 5], 2: [7], 7: [], 5: [6], 6: []})
8617+
sage: P.cuts()
8618+
[frozenset({3, 4, 5, 6, 7}),
8619+
frozenset({1, 2, 4, 6, 7}),
8620+
frozenset({4}),
8621+
frozenset({0, 2, 5, 6, 7}),
8622+
frozenset({2, 7}),
8623+
frozenset({7}),
8624+
frozenset({5, 6}),
8625+
frozenset({6}),
8626+
frozenset({4, 6, 7}),
8627+
frozenset({5, 6, 7}),
8628+
frozenset({2, 6, 7}),
8629+
frozenset(),
8630+
frozenset({6, 7}),
8631+
frozenset({0, 1, 2, 3, 4, 5, 6, 7})]
8632+
86138633
.. SEEALSO::
86148634
86158635
:meth:`completion_by_cuts`
86168636
"""
8617-
from sage.graphs.graph import Graph
8618-
from sage.graphs.independent_sets import IndependentSets
8619-
auxg = Graph({(u, 0): [(v, 1) for v in self if not self.ge(u, v)]
8620-
for u in self}, format='dict_of_lists')
8621-
auxg.add_vertices([(v, 1) for v in self])
8622-
return [frozenset([xa for xa, xb in c if xb == 0])
8623-
for c in IndependentSets(auxg, maximal=True)]
8637+
C, C2 = [], []
8638+
for x in self:
8639+
C.append(set(self.order_filter([x])))
8640+
for i, c in enumerate(C):
8641+
for j in range(i + 1, len(C)):
8642+
I = c.intersection(C[j])
8643+
if I not in C + C2:
8644+
C2.append(I)
8645+
while C2:
8646+
D = []
8647+
for x in C:
8648+
for y in C2:
8649+
I = x.intersection(y)
8650+
if all(I not in X for X in [C, C2, D]):
8651+
D.append(I)
8652+
C.extend(C2)
8653+
C2 = D
8654+
S = set(self)
8655+
if S not in C:
8656+
C.append(S)
8657+
return [frozenset(x) for x in C]
86248658

86258659
def completion_by_cuts(self):
86268660
"""

0 commit comments

Comments
 (0)