当前位置: 首页>>代码示例>>Python>>正文


Python Poset.canonical_label方法代码示例

本文整理汇总了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
开发者ID:bukzor,项目名称:sage,代码行数:53,代码来源:ordered_tree.py


注:本文中的sage.combinat.posets.posets.Poset.canonical_label方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。