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

use strings as label in modular-decomposition trees #37638

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/sage/combinat/rooted_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def __init__(self, parent=None, children=[], check=True):
try:
children = list(children)
except TypeError:
raise TypeError("input ({}) is not a valid tree".format(children))
raise TypeError(f"input ({children}) is not a valid tree")
#if not (children.__class__ is self.__class__
# and children.parent() == parent):
children = [self.__class__(parent, x) for x in children]
Expand All @@ -215,7 +215,7 @@ def sort_key(self):
.. NOTE::

The tree ``self`` must be normalized before calling this
method (see :meth:`normalize`). This doesn't matter
method (see :meth:`normalize`). This does not matter
unless you are inside the :meth:`clone` context manager,
because outside of it every rooted tree is already
normalized.
Expand Down Expand Up @@ -813,6 +813,10 @@ class LabelledRootedTree(AbstractLabelledClonableTree, RootedTree):

- ``label`` -- any hashable Sage object (default is ``None``)

.. NOTE::

It is required that all labels are comparable.

EXAMPLES::

sage: x = LabelledRootedTree([], label = 3); x
Expand Down Expand Up @@ -904,7 +908,7 @@ def sort_key(self):
.. NOTE::

The tree ``self`` must be normalized before calling this
method (see :meth:`normalize`). This doesn't matter
method (see :meth:`normalize`). This does not matter
unless you are inside the :meth:`clone` context manager,
because outside of it every rooted tree is already
normalized.
Expand Down
12 changes: 10 additions & 2 deletions src/sage/graphs/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8091,6 +8091,13 @@ def modular_decomposition(self, algorithm=None, style='tuple'):
(PRIME, [1, 2, 5, 6, 0, (PARALLEL, [3, 4])])
sage: G2.modular_decomposition()
(PRIME, [5, 6, 3, 4, 2, (PARALLEL, [0, 1])])

Check that :issue:`37631` is fixed::

sage: G = Graph('GxJEE?')
sage: G.modular_decomposition(style='tree')
PRIME[2[], SERIES[0[], 1[]], PARALLEL[3[], 4[]],
PARALLEL[5[], 6[], 7[]]]
"""
from sage.graphs.graph_decompositions.modular_decomposition import (NodeType,
habib_maurer_algorithm,
Expand Down Expand Up @@ -8129,14 +8136,15 @@ def relabel(x):
def to_tree(x):
if x.node_type == NodeType.NORMAL:
return LabelledRootedTree([], label=x.children[0])
return LabelledRootedTree([to_tree(y) for y in x.children], label=x.node_type)
return LabelledRootedTree([to_tree(y) for y in x.children],
label=x.node_type)

return to_tree(D)

raise ValueError("style must be 'tuple' or 'tree'")

@doc_index("Graph properties")
def is_polyhedral(self):
def is_polyhedral(self) -> bool:
"""
Check whether the graph is the graph of the polyhedron.

Expand Down
8 changes: 4 additions & 4 deletions src/sage/graphs/graph_decompositions/modular_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
# https://www.gnu.org/licenses/
# ****************************************************************************

from enum import Enum
from enum import Enum, IntEnum

from sage.misc.lazy_import import lazy_import
from sage.misc.random_testing import random_testing

lazy_import('sage.groups.perm_gps.permgroup_element', 'PermutationGroupElement')


class NodeType(Enum):
class NodeType(IntEnum):
"""
NodeType is an enumeration class used to define the various types of nodes
in modular decomposition tree.
Expand All @@ -45,7 +45,7 @@ class NodeType(Enum):
NORMAL = 3
FOREST = -1

def __repr__(self):
def __repr__(self) -> str:
r"""
String representation of this node type.

Expand Down
Loading