Skip to content

Commit 5089571

Browse files
author
Release Manager
committed
gh-36846: Resolve nice tree decomp bug in #36843, and allow `label_nice_tree_decomposition` to return a digraph This PR aims to resolve #36843, i.e., it now handles potential join nodes and singleton tree decomp correctly. This PR also allows `label_nice_tree_decomposition` to return a directed graph, and treats the root node as a `forget` node, simplifying algorithm implementation. <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #36846 Reported by: Jing Guo Reviewer(s): David Coudert, Dima Pasechnik, Jing Guo
2 parents 340cf1e + 2b6f2a9 commit 5089571

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

src/sage/graphs/graph_decompositions/tree_decomposition.pyx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,37 +1083,31 @@ def label_nice_tree_decomposition(nice_TD, root, directed=False):
10831083
EXAMPLES::
10841084
10851085
sage: from sage.graphs.graph_decompositions.tree_decomposition import make_nice_tree_decomposition, label_nice_tree_decomposition
1086-
sage: bip_one_four = graphs.CompleteBipartiteGraph(1, 4)
1087-
sage: bip_one_four_TD = bip_one_four.treewidth(certificate=True)
1088-
sage: nice_TD = make_nice_tree_decomposition(bip_one_four, bip_one_four_TD)
1086+
sage: claw = graphs.CompleteBipartiteGraph(1, 3)
1087+
sage: claw_TD = claw.treewidth(certificate=True)
1088+
sage: nice_TD = make_nice_tree_decomposition(claw, claw_TD)
10891089
sage: root = sorted(nice_TD.vertices())[0]
10901090
sage: label_TD = label_nice_tree_decomposition(nice_TD, root, directed=True)
1091-
sage: print(label_TD.name())
1092-
Labelled Nice tree decomposition of Tree decomposition
1093-
sage: for node in sorted(label_TD):
1091+
sage: label_TD.name()
1092+
'Labelled Nice tree decomposition of Tree decomposition'
1093+
sage: for node in sorted(label_TD): # random
10941094
....: print(node, label_TD.get_vertex(node))
10951095
(0, {}) forget
10961096
(1, {0}) forget
10971097
(2, {0, 1}) intro
10981098
(3, {0}) forget
1099-
(4, {0, 4}) join
1100-
(5, {0, 4}) intro
1101-
(6, {0, 4}) intro
1102-
(7, {0}) forget
1103-
(8, {0}) forget
1104-
(9, {0, 3}) intro
1105-
(10, {0, 2}) intro
1106-
(11, {3}) intro
1107-
(12, {2}) intro
1108-
(13, {}) leaf
1109-
(14, {}) leaf
1099+
(4, {0, 3}) intro
1100+
(5, {0}) forget
1101+
(6, {0, 2}) intro
1102+
(7, {2}) intro
1103+
(8, {}) leaf
11101104
"""
11111105
from sage.graphs.digraph import DiGraph
11121106
from sage.graphs.graph import Graph
11131107

11141108
directed_TD = DiGraph(nice_TD.breadth_first_search(start=root, edges=True),
11151109
format='list_of_edges',
1116-
name='Labelled {}'.format(nice_TD))
1110+
name='Labelled {}'.format(nice_TD.name()))
11171111

11181112
# The loop starts from the root node
11191113
# We assume the tree decomposition is valid and nice,

0 commit comments

Comments
 (0)