本文整理汇总了Python中sage.graphs.graph.Graph.is_clique方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.is_clique方法的具体用法?Python Graph.is_clique怎么用?Python Graph.is_clique使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.graph.Graph
的用法示例。
在下文中一共展示了Graph.is_clique方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _check_pbd
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import is_clique [as 别名]
def _check_pbd(B,v,S):
r"""
Checks that ``B`` is a PBD on `v` points with given block sizes.
INPUT:
- ``bibd`` -- a list of blocks
- ``v`` (integer) -- number of points
- ``S`` -- list of integers
EXAMPLE::
sage: designs.BalancedIncompleteBlockDesign(40,4).blocks() # indirect doctest
[[0, 1, 2, 12], [0, 3, 6, 9], [0, 4, 8, 10],
[0, 5, 7, 11], [0, 13, 26, 39], [0, 14, 25, 28],
[0, 15, 27, 38], [0, 16, 22, 32], [0, 17, 23, 34],
...
"""
from itertools import combinations
from sage.graphs.graph import Graph
if not all(len(X) in S for X in B):
raise RuntimeError("This is not a nice honest PBD from the good old days !")
g = Graph()
m = 0
for X in B:
g.add_edges(list(combinations(X,2)))
if g.size() != m+binomial(len(X),2):
raise RuntimeError("This is not a nice honest PBD from the good old days !")
m = g.size()
if not (g.is_clique() and g.vertices() == range(v)):
raise RuntimeError("This is not a nice honest PBD from the good old days !")
return B
示例2: _check_pbd
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import is_clique [as 别名]
def _check_pbd(B,v,S):
r"""
Checks that ``B`` is a PBD on ``v`` points with given block sizes ``S``.
The points of the balanced incomplete block design are implicitely assumed
to be `\{0, ..., v-1\}`.
INPUT:
- ``B`` -- a list of blocks
- ``v`` (integer) -- number of points
- ``S`` -- list of integers `\geq 2`.
EXAMPLE::
sage: designs.balanced_incomplete_block_design(40,4).blocks() # indirect doctest
[[0, 1, 2, 12], [0, 3, 6, 9], [0, 4, 8, 10],
[0, 5, 7, 11], [0, 13, 26, 39], [0, 14, 25, 28],
[0, 15, 27, 38], [0, 16, 22, 32], [0, 17, 23, 34],
...
sage: from sage.combinat.designs.bibd import _check_pbd
sage: _check_pbd([[1],[]],1,[1,0])
Traceback (most recent call last):
...
RuntimeError: All integers of S must be >=2
TESTS::
sage: _check_pbd([[1,2]],2,[2])
Traceback (most recent call last):
...
RuntimeError: The PBD covers a point 2 which is not in {0, 1}
sage: _check_pbd([[1,2]]*2,2,[2])
Traceback (most recent call last):
...
RuntimeError: The pair (1,2) is covered more than once
sage: _check_pbd([],2,[2])
Traceback (most recent call last):
...
RuntimeError: The pair (0,1) is not covered
sage: _check_pbd([[1,2],[1]],2,[2])
Traceback (most recent call last):
...
RuntimeError: A block has size 1 while S=[2]
"""
from itertools import combinations
from sage.graphs.graph import Graph
for X in B:
if len(X) not in S:
raise RuntimeError("A block has size {} while S={}".format(len(X),S))
if any(x < 2 for x in S):
raise RuntimeError("All integers of S must be >=2")
if v == 0 or v == 1:
if B:
raise RuntimeError("A PBD with v<=1 is expected to be empty.")
g = Graph()
g.add_vertices(range(v))
m = 0
for X in B:
for i,j in combinations(X,2):
g.add_edge(i,j)
m_tmp = g.size()
if m_tmp != m+1:
raise RuntimeError("The pair ({},{}) is covered more than once".format(i,j))
m = m_tmp
if g.vertices() != range(v):
from sage.sets.integer_range import IntegerRange
p = (set(g.vertices())-set(range(v))).pop()
raise RuntimeError("The PBD covers a point {} which is not in {}".format(p,IntegerRange(v)))
if not g.is_clique():
for p1 in g:
if g.degree(p1) != v-1:
break
neighbors = g.neighbors(p1)+[p1]
p2 = (set(g.vertices())-set(neighbors)).pop()
raise RuntimeError("The pair ({},{}) is not covered".format(p1,p2))
return B