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


Python Graph.complement方法代码示例

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


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

示例1: CompleteMultipartiteGraph

# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import complement [as 别名]
def CompleteMultipartiteGraph(l):
    r"""
    Returns a complete multipartite graph.

    INPUT:

    - ``l`` -- a list of integers : the respective sizes
      of the components.

    EXAMPLE:

    A complete tripartite graph with sets of sizes
    `5, 6, 8`::

        sage: g = graphs.CompleteMultipartiteGraph([5, 6, 8]); g
        Multipartite Graph with set sizes [5, 6, 8]: Graph on 19 vertices

    It clearly has a chromatic number of 3::

        sage: g.chromatic_number()
        3
    """
    g = Graph()
    for i in l:
        g = g + CompleteGraph(i)

    g = g.complement()
    g.name("Multipartite Graph with set sizes "+str(l))

    return g
开发者ID:JoseGuzman,项目名称:sage,代码行数:32,代码来源:basic.py

示例2: CompleteMultipartiteGraph

# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import complement [as 别名]
def CompleteMultipartiteGraph(l):
    r"""
    Returns a complete multipartite graph.

    INPUT:

    - ``l`` -- a list of integers : the respective sizes
      of the components.

    EXAMPLE:

    A complete tripartite graph with sets of sizes
    `5, 6, 8`::

        sage: g = graphs.CompleteMultipartiteGraph([5, 6, 8]); g
        Multipartite Graph with set sizes [5, 6, 8]: Graph on 19 vertices

    It clearly has a chromatic number of 3::

        sage: g.chromatic_number()
        3
    """
    
    n = sum(l) #getting the number of vertices
    r = len(l) #getting the number of partitions
    positions = {}

    if r > 2: #position code gives bad results on bipartite or isolated graphs

        '''
        Produce a layout of the vertices so that vertices in the same
        vertex set are adjecent and clearly separated from vertices in other
        vertex sets.

        This is done by calculating the vertices of an r-gon then
        calculating the slope between adjacent vertices. We then 'walk'
        around the r-gon placing graph vertices in regular intervals between 
        adjacent vertices of the r-gon.

        Makes a nicely organized graph like in this picture: 
        https://commons.wikimedia.org/wiki/File:Turan_13-4.svg
        '''

        points = [[cos(2*pi*i/r),sin(2*pi*i/r)] for i in range(r)]
        slopes = [[(points[(i+1)%r][0]-points[i%r][0]),
                   (points[(i+1)%r][1]-points[i%r][1])] for i in range(r)]

        counter = 0

        for i in range(len(l)):
            vertex_set_size = l[i]+1
            for j in range(1,vertex_set_size):
                x = points[i][0]+slopes[i][0]*j/(vertex_set_size)
                y = points[i][1]+slopes[i][1]*j/(vertex_set_size)
                positions[counter] = (x,y)
                counter += 1

    g = Graph()
    for i in l:
        g = g + CompleteGraph(i)

    g = g.complement()
    g.set_pos(positions)
    g.name("Multipartite Graph with set sizes "+str(l))



    return g
开发者ID:drupel,项目名称:sage,代码行数:70,代码来源:basic.py


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