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


Python Graph.neighbor_iterator方法代码示例

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


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

示例1: nauty

# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import neighbor_iterator [as 别名]

#.........这里部分代码省略.........
          program with some information on the arguments, while a line beginning
          with ">E" indicates an error with the input.

        - ``options`` -- string (default: ``""``) -- anything else that should
          be forwarded as input to Nauty's genbg. See its documentation for more
          information : `<http://cs.anu.edu.au/~bdm/nauty/>`_.

          .. NOTE::

              For genbg the *first class* elements are vertices, and *second
              class* elements are the hypergraph's sets.

        OUTPUT:

        A tuple of tuples.

        EXAMPLES:

        Small hypergraphs::

            sage: list(hypergraphs.nauty(4, 2))
            [((), (0,), (1,), (0, 1))]

        Only connected ones::

            sage: list(hypergraphs.nauty(2, 2, connected=True))
            [((0,), (0, 1))]

        Non-empty sets only::

            sage: list(hypergraphs.nauty(3, 2, set_min_size=1))
            [((0,), (1,), (0, 1))]

        The Fano Plane, as the only 3-uniform hypergraph with 7 sets and 7
        vertices::

            sage: fano = next(hypergraphs.nauty(7, 7, uniform=3, max_intersection=1))
            sage: print(fano)
            ((0, 1, 2), (0, 3, 4), (0, 5, 6), (1, 3, 5), (2, 4, 5), (2, 3, 6), (1, 4, 6))

        The Fano Plane, as the only 3-regular hypergraph with 7 sets and 7
        vertices::

            sage: fano = next(hypergraphs.nauty(7, 7, regular=3, max_intersection=1))
            sage: print(fano)
            ((0, 1, 2), (0, 3, 4), (0, 5, 6), (1, 3, 5), (2, 4, 5), (2, 3, 6), (1, 4, 6))
        """
        import subprocess

        nauty_input = options

        if connected:
            nauty_input += " -c"

        if not multiple_sets:
            nauty_input += " -z"

        if max_intersection is not None:
            nauty_input += " -Z" + str(max_intersection)

        # degrees and sizes
        if regular is not False:
            vertex_max_degree = vertex_min_degree = regular
        if vertex_max_degree is None:
            vertex_max_degree = number_of_sets
        if vertex_min_degree is None:
            vertex_min_degree = 0

        if uniform is not False:
            set_max_size = set_min_size = uniform
        if set_max_size is None:
            set_max_size = number_of_vertices
        if set_min_size is None:
            set_min_size = 0

        nauty_input += " -d" + str(vertex_min_degree) + ":" + str(set_min_size)
        nauty_input += " -D" + str(vertex_max_degree) + ":" + str(set_max_size)

        nauty_input +=  " " + str(number_of_vertices) + " " + str(number_of_sets) + " "

        sp = subprocess.Popen("genbg {0}".format(nauty_input), shell=True,
                              stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE, close_fds=True)

        if debug:
            yield sp.stderr.readline()

        gen = sp.stdout
        total = number_of_sets + number_of_vertices
        from sage.graphs.graph import Graph
        while True:
            try:
                s = next(gen)
            except StopIteration:
                # Exhausted list of graphs from nauty geng
                return

            G = Graph(s[:-1], format='graph6')

            yield tuple(tuple(G.neighbor_iterator(v)) for v in range(number_of_vertices, total))
开发者ID:sagemath,项目名称:sage,代码行数:104,代码来源:hypergraph_generators.py


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