本文整理汇总了Python中sage.graphs.all.DiGraph.reverse方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.reverse方法的具体用法?Python DiGraph.reverse怎么用?Python DiGraph.reverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.all.DiGraph
的用法示例。
在下文中一共展示了DiGraph.reverse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IntegerPartitions
# 需要导入模块: from sage.graphs.all import DiGraph [as 别名]
# 或者: from sage.graphs.all.DiGraph import reverse [as 别名]
def IntegerPartitions(n):
"""
Returns the poset of integer partitions on the integer ``n``.
A partition of a positive integer `n` is a non-increasing list
of positive integers that sum to `n`. If `p` and `q` are
integer partitions of `n`, then `p` covers `q` if and only
if `q` is obtained from `p` by joining two parts of `p`
(and sorting, if necessary).
EXAMPLES::
sage: P = Posets.IntegerPartitions(7); P
Finite poset containing 15 elements
sage: len(P.cover_relations())
28
"""
def lower_covers(partition):
r"""
Nested function for computing the lower covers
of elements in the poset of integer partitions.
"""
lc = []
for i in range(0,len(partition)-1):
for j in range(i+1,len(partition)):
new_partition = partition[:]
del new_partition[j]
del new_partition[i]
new_partition.append(partition[i]+partition[j])
new_partition.sort(reverse=True)
tup = tuple(new_partition)
if tup not in lc:
lc.append(tup)
return lc
from sage.combinat.partition import partitions_list
H = DiGraph(dict([[tuple(p),lower_covers(p)] for p in
partitions_list(n)]))
return Poset(H.reverse())
示例2: RestrictedIntegerPartitions
# 需要导入模块: from sage.graphs.all import DiGraph [as 别名]
# 或者: from sage.graphs.all.DiGraph import reverse [as 别名]
def RestrictedIntegerPartitions(n):
"""
Returns the poset of integer partitions on the integer `n`
ordered by restricted refinement. That is, if `p` and `q`
are integer partitions of `n`, then `p` covers `q` if and
only if `q` is obtained from `p` by joining two distinct
parts of `p` (and sorting, if necessary).
EXAMPLES::
sage: P = Posets.RestrictedIntegerPartitions(7); P
Finite poset containing 15 elements
sage: len(P.cover_relations())
17
"""
def lower_covers(partition):
r"""
Nested function for computing the lower covers of elements in the
restricted poset of integer partitions.
"""
lc = []
for i in range(0,len(partition)-1):
for j in range(i+1,len(partition)):
if partition[i] != partition[j]:
new_partition = partition[:]
del new_partition[j]
del new_partition[i]
new_partition.append(partition[i]+partition[j])
new_partition.sort(reverse=True)
tup = tuple(new_partition)
if tup not in lc:
lc.append(tup)
return lc
from sage.combinat.partition import Partitions
H = DiGraph(dict([[tuple(p),lower_covers(p)] for p in
Partitions(n)]))
return Poset(H.reverse())