Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function make_nice_tree_decomposition returns incorrect results for $K_{3}$ and $K_{2, 5}$ #36843

Closed
guojing0 opened this issue Dec 9, 2023 · 2 comments · Fixed by #36846
Closed

Comments

@guojing0
Copy link
Contributor

guojing0 commented Dec 9, 2023

I am implementing homomorphism counting functionality, and noticed that currently the function make_nice_tree_decomposition does not work correctly for $K_{3}$ and $K_{2, 5}$:

graph = graphs.CompleteBipartiteGraph(2, 5)  # replace by `graphs.CompleteGraph(3)` for the triangle
tree_decomp = graph.treewidth(certificate=True)
nice_tree_decomp = make_nice_tree_decomposition(graph, tree_decomp)
root = sorted(nice_tree_decomp)[0]
dir_labelled_TD = label_nice_tree_decomposition(nice_tree_decomp, root)
dir_labelled_TD.plot()

图片

When it's $K_{3}$, it only returns a singleton.

@guojing0 guojing0 added this to the sage-10.3 milestone Dec 9, 2023
@guojing0 guojing0 self-assigned this Dec 9, 2023
@guojing0 guojing0 changed the title Function make_nice_tree_decomposition returns incorrect results for K_3 and K_(2, 5) Function make_nice_tree_decomposition returns incorrect results for $K_{3}$ and $K_{2, 5}$ Dec 9, 2023
@RuchitJagodara
Copy link
Contributor

RuchitJagodara commented Dec 9, 2023

dir_labelled_TD = label_nice_tree_decomposition(nice_tree_decomp, root, directed=True)

Here, you are passing three arguments in label_nice_tree_decomposition but it is giving me an error in my case, it says that 'label_nice_tree_decomposition() got an unexpected keyword argument 'directed'.' Can you mention the version which you are using currently, @guojing0 because I am not able to reproduce the same in my case.

sage: graph = graphs.CompleteBipartiteGraph(2, 5)
....: tree_decomp = graph.treewidth(certificate=True)
....: nice_tree_decomp = make_nice_tree_decomposition(graph, tree_decomp)
....: root = sorted(nice_tree_decomp)[0]
....: dir_labelled_TD = label_nice_tree_decomposition(nice_tree_decomp, root, directed=True)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[26], line 5
      3 nice_tree_decomp = make_nice_tree_decomposition(graph, tree_decomp)
      4 root = sorted(nice_tree_decomp)[Integer(0)]
----> 5 dir_labelled_TD = label_nice_tree_decomposition(nice_tree_decomp, root, directed=True)

File ~/sage/sage/src/sage/graphs/graph_decompositions/tree_decomposition.pyx:1014, in sage.graphs.graph_decompositions.tree_decomposition.label_nice_tree_decomposition()
   1012     return nice_tree_decomp
   1013 
-> 1014 def label_nice_tree_decomposition(nice_TD, root):
   1015     r"""
   1016     Return a nice tree decomposition with nodes labelled accordingly.

TypeError: label_nice_tree_decomposition() got an unexpected keyword argument 'directed'

@guojing0
Copy link
Contributor Author

guojing0 commented Dec 9, 2023

@RuchitJagodara Thank you for pointing out. I just changed the code. It should work now.

guojing0 added a commit to guojing0/sage that referenced this issue Dec 9, 2023
@vbraun vbraun closed this as completed in 1abf5c6 Dec 14, 2023
vbraun pushed a commit to vbraun/sage that referenced this issue Dec 17, 2023
… allow `label_nice_tree_decomposition` to return a digraph

    
This PR aims to resolve sagemath#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 sagemath#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 sagemath#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
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36846
Reported by: Jing Guo
Reviewer(s): David Coudert, Dima Pasechnik, Jing Guo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment