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


Python Graph.degree方法代码示例

本文整理汇总了Python中sage.graphs.graph.Graph.degree方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.degree方法的具体用法?Python Graph.degree怎么用?Python Graph.degree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sage.graphs.graph.Graph的用法示例。


在下文中一共展示了Graph.degree方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _check_pbd

# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import degree [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
开发者ID:Etn40ff,项目名称:sage,代码行数:88,代码来源:bibd.py


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