sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.36k stars 462 forks source link

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

Closed guojing0 closed 9 months ago

guojing0 commented 10 months ago

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.

RuchitJagodara commented 10 months ago

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 commented 10 months ago

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