本文整理汇总了Python中sage.combinat.posets.posets.Poset.canonical_label方法的典型用法代码示例。如果您正苦于以下问题:Python Poset.canonical_label方法的具体用法?Python Poset.canonical_label怎么用?Python Poset.canonical_label使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.combinat.posets.posets.Poset
的用法示例。
在下文中一共展示了Poset.canonical_label方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_poset
# 需要导入模块: from sage.combinat.posets.posets import Poset [as 别名]
# 或者: from sage.combinat.posets.posets.Poset import canonical_label [as 别名]
def to_poset(self, root_to_leaf = False):
r"""
Return the poset obtained by interpreting the tree as a hasse
diagram. The default orientation is from leaves to root but you can
pass ``root_to_leaf=True`` to obtain the inverse orientation.
INPUT:
- ``root_to_leaf`` -- boolean, true if the poset orientation should
be from root to leaves. It is false by default.
EXAMPLES::
sage: t = OrderedTree([])
sage: t.to_poset()
Finite poset containing 1 elements
sage: p = OrderedTree([[[]],[],[]]).to_poset()
sage: p.cover_relations()
[[3, 4], [2, 4], [0, 1], [1, 4]]
sage: p = OrderedTree([[[]],[],[]]).to_poset(root_to_leaf=True)
sage: p.cover_relations()
[[0, 1], [0, 2], [0, 3], [3, 4]]
If the tree is labelled, we use its labelling to label the poset.
Otherwise, we use the poset canonical labelling::
sage: t = OrderedTree([[[]],[],[]]).canonical_labelling()
sage: t
1[2[3[]], 4[], 5[]]
sage: t.to_poset().cover_relations()
[[5, 1], [4, 1], [3, 2], [2, 1]]
"""
if self in LabelledOrderedTrees():
relabel = False
else:
self = self.canonical_labelling()
relabel = True
relations = []
elements = [self.label()]
roots = [self]
while len(roots)!=0:
node = roots.pop()
for child in node:
elements.append(child.label())
relations.append((node.label(),child.label()) if root_to_leaf else (child.label(),node.label()))
roots.append(child)
from sage.combinat.posets.posets import Poset
p = Poset([elements, relations])
if relabel:
p = p.canonical_label()
return p